-
Notifications
You must be signed in to change notification settings - Fork 96
/
6.7.cpp
71 lines (64 loc) · 1.55 KB
/
6.7.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
/*
* 题目名称:约数的个数
* 题目来源:清华大学复试上机题
* 题目链接:http://t.cn/Aip7dTUp
* 代码作者:杨泽邦(炉灰)
*/
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
using namespace std;
const int MAXN = 4e4;
vector<int> prime; //保存质数
bool isPrime[MAXN]; //标记数组
void Initial() {
for (int i = 0; i < MAXN; ++i) { //初始化
isPrime[i] = true;
}
isPrime[0] = false;
isPrime[1] = false;
for (int i = 2; i < MAXN; ++i) {
if (!isPrime[i]) { //非质数则跳过
continue;
}
prime.push_back(i);
if (i > MAXN / i) {
continue;
}
for (int j = i * i; j < MAXN; j += i) {
isPrime[j] = false; //质数的倍数为非质数
}
}
return ;
}
int NumberOfFactor(int number) {
int answer = 1;
for (int i = 0; i < prime.size() && prime[i] <= number; ++i) {
int exponent = 0;
while (number % prime[i] == 0) {
exponent++;
number /= prime[i];
}
answer *= exponent + 1;
}
if (number > 1) {
answer *= 2;
}
return answer;
}
int main() {
Initial();
int n;
while (scanf("%d", &n) != EOF) {
if (n == 0) {
break;
}
for (int i = 0; i < n; ++i) {
int number;
scanf("%d", &number);
printf("%d\n", NumberOfFactor(number));
}
}
return 0;
}