forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path64.cpp
More file actions
71 lines (59 loc) · 1.14 KB
/
64.cpp
File metadata and controls
71 lines (59 loc) · 1.14 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
65
66
67
68
69
70
71
#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)
string i2s(int n) {
stringstream ss;
ss << n;
string res;
ss >> res;
return res;
}
map<string, int> dic;
map<string, int>::iterator itr;
string getStr(int a, int b, int c) {
return i2s(a) + "," + i2s(b) + "," + i2s(c);
}
int doit(int n) {
dic.clear();
int a = (int) sqrt(n + 0.0);
if (a * a == n) return 0;
int b = a, c = 1;
int idx = 0;
string s = getStr(a, b, c);
dic[s] = idx++;
while (true) {
int a1 = c, b1 = b, c1 = n - b * b;
c1 /= a1;
a = (int)((sqrt(n + 0.0) + b1) / c1);
b = a * c1 - b1;
c = c1;
string s = getStr(a, b, c);
itr = dic.find(s);
if (itr == dic.end()) {
dic[s] = idx++;
} else {
return idx - dic[s];
}
}
}
void run() {
int res = 0;
FOR(i,1,10000) {
int t = doit(i);
//if (i % 1000 == 0) cout << i << " " << t << endl;
if ((t & 1) == 1) ++res;
}
cout << res << endl;
}
int main () {
run();
return 0;
}