forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path108.cpp
More file actions
64 lines (57 loc) · 1.06 KB
/
108.cpp
File metadata and controls
64 lines (57 loc) · 1.06 KB
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
#include <iostream>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
int plist[10000],pcount=0;
int prime(int n){
int i;
if ((n!=2&&!(n%2))||(n!=3&&!(n%3))||(n!=5&&!(n%5))||(n!=7&&!(n%7)))
return 0;
for (i=0;plist[i]*plist[i]<=n;i++)
if (!(n%plist[i]))
return 0;
return n>1;
}
void initprime(){
int i;
for (plist[pcount++]=2,i=3;i<50000;i++)
if (prime(i))
plist[pcount++]=i;
}
int doit(int n) {
int ret = 1;
int end = (int) sqrt(n + 0.0);
FOR(i,0,pcount-1) {
if (plist[i] > end) break;
if (n == 1) break;
int cnt = 0;
while (n % plist[i] == 0) {
++cnt;
n /= plist[i];
}
ret *= (cnt << 1) + 1;
}
if (n != 1) ret *= 3;
return ((ret - 1) >> 1) + 1;
}
void run() {
initprime();
FOR(i,1,1000000) {
int t = doit(i);
if (t > 1000) {
cout << i << " " << t << endl;
break;
}
}
}
int main () {
run();
return 0;
}