forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path120.cpp
More file actions
64 lines (58 loc) · 1.08 KB
/
120.cpp
File metadata and controls
64 lines (58 loc) · 1.08 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 REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define RFOR(i,a,b) for(int i=(a);i>=(b);--i)
typedef long long LL;
LL s2i(string s) {
stringstream ss;
ss << s;
LL res;
ss >> res;
return res;
}
string i2s(LL n) {
stringstream ss;
ss << n;
string res;
ss >> res;
return res;
}
int doit(int n) {
int n2 = n * n;
int a = n - 1, b = n + 1;
int ta = a, tb = b;
int ret = (ta + tb) % n2;
map<pair<int, int>, int> mm;
map<pair<int, int>, int>::iterator itr;
while (true) {
itr = mm.find(make_pair(ta, tb));
if (itr != mm.end()) break;
mm[make_pair(ta, tb)] = 1;
ret = max(ret, (ta + tb) % n2);
ta = ta * a % n2;
tb = tb * b % n2;
}
return ret;
}
void run() {
int res = 0;
FOR(a,3,1000) {
int t = doit(a);
//cout << a << " " << t << endl;
res += t;
}
cout << res << endl;
}
int main () {
run();
return 0;
}