-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathariprog.cpp
executable file
·54 lines (51 loc) · 1.11 KB
/
ariprog.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
/*
ID: paulius10
PROG: ariprog
LANG: C++
*/
#include <fstream>
#include <set>
#include <utility>
using namespace std;
int main() {
ifstream fin("ariprog.in");
int N, M;
fin >> N >> M;
int MAX = 2 * M * M;
fin.close();
set<pair<int, int> > progressions;
bool bisquary[MAX + 1];
for (int i = 0; i <= MAX; i++)
bisquary[i] = false;
for (int p = 0; p <= M; p++) {
for (int q = 0; q <= M; q++) {
bisquary[p * p + q * q] = true;
}
}
for (int a = 0; a < MAX; a++) {
if (!bisquary[a]) continue;
for (int b = 1; a + (N - 1) * b <= MAX; b++) {
bool wrong = false;
int max_n = a + (N - 1) * b;
for (int n = a + b; n <= max_n; n += b) {
if (!bisquary[n]) {
wrong = true;
break;
}
}
if (!wrong) {
progressions.insert(make_pair(b, a));
}
}
}
ofstream fout("ariprog.out");
if (progressions.size()) {
for (set<pair<int, int> >::iterator it = progressions.begin(); it != progressions.end(); it++) {
fout << (*it).second << " " << (*it).first << endl;
}
} else {
fout << "NONE" << endl;
}
fout.close();
return 0;
}