1/**//*思路:利用筛选法求得一个数的各因子之和,然后存入到数组中直接访问输出
2//1.经典
3#include <stdio.h>
4#include <stdlib.h>
5#define N 500000
6
7int factors[500001] = {0};
8int main ()
9{
10 factors[0] = 0; factors[1] = 0;
11 for (int i = 2; i < N + 1; i ++)
12 {
13 factors[i] = 1;
14 }
15
16 for (int i = 2; i <= (N + 1) / 2; i ++)
17 {
18 for (int j = 2 * i; j < N + 1; j += i)
19 {
20 factors[j] += i;
21 }
22 }
23
24 int t, n;
25 while ( scanf ("%d", &t) != EOF )
26 {
27 for (int i = 0; i < t; i ++)
28 {
29 scanf ("%d", &n);
30 printf ("%d\n", factors[n]);
31 }
32 }
33 //system("pause");
34 return 0;
35}*/
36//2.蛮力搜索
37#include<stdio.h>
38#include<stdio.h>
39int main ()
40{
41int t, n;
42while ( scanf ("%d", &t) != EOF )
43{
44 int i , j, m;
45 for ( i = 0; i < t; i ++)
46 {
47 scanf ("%d", &n);
48 if (n == 1 )
49 printf ("%d\n", 0);
50 else
51 {
52 int factors = 1;
53 for (j = 2; j*j <= n; j++)
54 {
55 if (n % j == 0)
56 {
57 factors += n / j + j;
58 }
59 }
60
61 if ( (j - 1) * (j - 1) == n )
62 factors = factors - ( j - 1); 例如:n = 16时
63
64 printf ("%d\n", factors);
65 }
66 }
67}
68//system (pause);
69return 0;
70}
71
posted on 2010-08-21 11:41
雪黛依梦 阅读(224)
评论(0) 编辑 收藏 引用