0
0
0
1. 云栖社区>
2. 博客>
3. 正文

## 九度oj 题目1087：约数的个数

```5
1 3 4 6 12```

```1
2
3
4
6```

``` 1 /*
2  * Main.c
3  *
4  *  Created on: 2014年1月15日
5  *      Author: Shaobo
6  */
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <math.h>
10
11 int main(void){
12     int N;
13     int * data = NULL;
14     int i, j;
15     int cnt, tmp;
16
17     while (scanf("%d", &N) == 1 && N != 0){
18         data = (int *)malloc(sizeof(int) * N);
19         if (data == NULL)
20             break;
21         for (i=0; i<N; ++i)
22             scanf("%d", &data[i]);
23         for (i=0; i<N; ++i){
24             cnt = 0;
25             for (j=1; j<=(int)sqrt(data[i]*1.0); ++j){
26                 if (data[i] % j == 0){
27                     cnt = cnt + 2;
28                 }
29             }
30             tmp = (int)(sqrt(data[i]*1.0));
31             if (tmp * tmp == data[i])
32                 --cnt;
33             printf("%d\n", cnt);
34         }
35         free(data);
36     }
37     return 0;
38 }```

``` 1 int main(void)
2 {
3     int N;
4     int i, j;
5     int cnt;
6
7     int num;
8     int t;
9     while (scanf("%d", &N) == 1 && N != 0)
10     {
11         for (i=0; i<N; ++i)
12         {
13             scanf("%d", &num);
14             cnt =1;
15             for (j=2; j<=num;j++)
16             {
17                 t=0;
18                 while(num % j==0)
19                 {
20                     t++;
21                     num=num/j;
22                 }
23                 cnt = cnt*(t+1);
24             }
25             printf("%d\n", cnt);
26         }
27     }
28     return 0;
29 }```

``` 1 int main(void)
2 {
3     int N;
4     int i, j;
5     int cnt;
6
7     int num;
8     int t;
9     while (scanf("%d", &N) == 1 && N != 0)
10     {
11         for (i=0; i<N; ++i)
12         {
13             scanf("%d", &num);
14             cnt =1;
15             for (j=2; j*j<=num;j++)
16             {
17                 t=0;
18                 while(num % j==0)
19                 {
20                     t++;
21                     num=num/j;
22                 }
23                 cnt = cnt*(t+1);
24             }
25             if(num>1) cnt=cnt*2;
26             printf("%d\n", cnt);
27         }
28     }
29     return 0;
30 }```

+ 关注