/*
ID:
PROG: ariprog
LANG: C++11
*/
#include <iostream>
#include <cstdio>
using namespace std;
int main() {
freopen("ariprog.in", "r", stdin);
freopen("ariprog.out", "w", stdout);
int n;
int m;
bool pq[127000] = {};
cin >> n >> m;
int squareNum = 0;
for (int i = 0; i <= m; i ++){
for (int j = i; j <= m; j ++){
pq[i*i + j*j] = true;
}
}
int step;
int start;
int maxInPq = m*m + m*m;
// cout << maxInPq << endl;
bool b = false;
for (step = 1; step <= maxInPq; step ++){
for (start = 0; start <= maxInPq; start ++){
if (start + (n-1) * step > maxInPq)
break;
if (!pq[start])
continue;
int i, pos = start;
for (i = 1; i < n && pq[pos]; i ++){
pos += step;
}
if (i == n && pq[pos]){
printf("%d %d\n", start, step);
//cout << start << endl;
b = true;
}
}
}
if (!b)
cout << "NONE" << endl;
return 0;
}
【USACO】Arithmetic Progressions
最新推荐文章于 2020-04-30 12:46:43 发布