-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path!test.cpp
80 lines (69 loc) · 1.5 KB
/
!test.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
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
ofstream fout("!test.out");
int gcd(int a, int b)
{
while(b != 0)
{
int r = b;
b = a % b;
a = r;
}
return a;
}
struct nums
{
int a;
int b;
int c;
// bool operator<(const nums & newNum) const
// {
// if (a != newNum.a)
// {
// return a < newNum.a;
// }
// else
// {
// return b < newNum.b;
// }
// };
bool operator<(const nums & newNum) const
{
int size1 = (to_string(b) + to_string(c)).size();
int size2 = (to_string(newNum.b) + to_string(newNum.c)).size();
if (size1 != size2)
{
return size1 < size2;
}
else
{
return a < newNum.a;
}
};
};
int main()
{
set<nums> store;
for (int i = 2; i <= 10000; ++i)
{
int a = 2 * i, b = i * i - 1, c = i * i + 1;
int allGcd = gcd(gcd(a, b), gcd(a, c));
a /= allGcd; b /= allGcd; c /= allGcd;
nums temp{min(a, b), max(a, b), c};
store.insert(temp);
}
for (auto it = store.begin(); it != store.end(); ++it)
{
fout << it->a << ' ' << it->b << ' ' << it->c << '\n';
}
return 0;
}