标签:style class code http tar color
题意:给定一个因子和,求出对应是哪个数字
思路:数字不可能大于因子和,对于每个数字去算出因子和,然后记录下来即可
代码:
#include <stdio.h>
#include <string.h>
const int N = 1005;
int n, ans[N];
void init() {
memset(ans, -1, sizeof(ans));
for (int i = 1; i <= 1000; i++) {
int sum = 0;
for (int j = 1; j <= i; j++) {
if (i % j == 0)
sum += j;
}
if (sum <= 1000) ans[sum] = i;
}
}
int main() {
int cas = 0;
init();
while (~scanf("%d", &n) && n) {
printf("Case %d: %d\n", ++cas, ans[n]);
}
return 0;
}
UVA 11728 - Alternate Task (数论),布布扣,bubuko.com
UVA 11728 - Alternate Task (数论)
标签:style class code http tar color
原文地址:http://blog.csdn.net/accelerator_/article/details/30572801