-
Notifications
You must be signed in to change notification settings - Fork 34
/
1028-Trailing-Zeroes-2.cpp
86 lines (58 loc) · 1.03 KB
/
1028-Trailing-Zeroes-2.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <vector>
#include <stdio.h>
#define sroot 1000007
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
vector <int> primes;
int sieve()
{
bool a[sroot];
memset(a, 0, sizeof(a));
for(int i = 2; i <= sroot; i++) {
if(a[i] == 0) {
for (int j = i + i; j <= sroot; j = j + i) {
a[j] = 1;
}
}
}
for (int i = 2; i <= sroot; i++) {
if(a[i] == 0) {
primes.push_back(i);
}
}
sort(primes.begin(), primes.end());
}
int main()
{
sieve();
int t;
long long x;
long long sum;
long long k;
long long temp;
long long n;
scanf("%d", &t);
for (int cases = 1; cases <= t; cases++) {
scanf("%lld", &x);
sum = 1;
n = sqrt(x);
for(int i = 0; i <= primes.size() - 1 and primes[i] <= n ; i++) {
k = 0;
if(x < primes[i]) {
break;
}
while(x % primes[i] == 0) {
x = x / primes[i];
k++;
}
sum = sum * (k + 1);
}
if(x > 1) sum *= 2;
cout << x << endl;
sum = sum - 1;
printf("Case %d: %lld\n",cases, sum);
}
}