题目链接:uva 11728 - Alternate Task
题目大意:给出S,求N,要求N所有的因子和为S。
解题思路:枚举因子i,所有整除i的数和加上i。
#include <cstdio>
#include <cstring>
const int N = 1005;
int n, c[N], v[N];
void init () {
memset(c, 0, sizeof(c));
memset(v, -1, sizeof(v));
for (int i = 1; i < N; i++) {
for (int j = i; j < N; j += i)
c[j] += i;
if (c[i] < N)
v[c[i]] = i;
}
}
int main () {
init();
int cas = 1;
while (scanf("%d", &n) == 1 && n) {
printf("Case %d: %d\n", cas++, v[n]);
}
return 0;
}
uva 11728 - Alternate Task(数论),布布扣,bubuko.com
uva 11728 - Alternate Task(数论)
原文地址:http://blog.csdn.net/keshuai19940722/article/details/36409469