forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path75.cpp
More file actions
64 lines (58 loc) · 1.34 KB
/
75.cpp
File metadata and controls
64 lines (58 loc) · 1.34 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;
#define MAXN 2000000
int gcd(int a, int b) {
while (true) {
if (b == 0) break;
a %= b;
a ^= b ^= a ^= b;
}
return a;
}
map<int, set<pair<int, pair<int, int> > > > dic;
void run() {
FOR(i,1,MAXN) dic[i] = set<pair<int, pair<int, int> > >();
FOR(m,2,1000) {
//cout << m << endl;
FOR(n,1,m-1) {
if (gcd(m, n) != 1) continue;
int a = 2 * m * n;
int b = m * m - n * n;
int c = m * m + n * n;
if (a > b) a ^= b ^= a ^= b;
if (a > c) a ^= c ^= a ^= c;
if (b > c) b ^= c ^= b ^= c;
//cout << a << " " << b << " " << c << endl;
int total = a + b + c;
int _a = a, _b = b, _c = c, _t = total;
while (total <= MAXN) {
dic[total].insert(make_pair(a, make_pair(b, c)));
a += _a, b += _b, c += _c, total += _t;
}
}
}
int res = 0;
FOR(i,1,MAXN) {
if (dic[i].size() == 1) ++res;
}
cout << "**" << endl;
cout << dic[120].size() << endl;
cout << "**" << endl;
cout << res << endl;
}
int main () {
run();
return 0;
}