标签:
/*
ID: awsd1231
PROG: ariprog
LANG: C++
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<set>
using namespace std;
int n, m;//等差数列长度,双平方数上界
struct T {
int a, b;
}ans[10005];
bool may[125005] = {0};
set<int> list;
void fill(int x) {
int t = 0;
for(int i = 0; i != x + 1; ++i)
for(int j = 0; j != x + 1; ++j) {
may[i*i + j*j] = 1;
list.insert(i*i + j*j);
}
}
bool check(int x, int y) {
int ni = 0;
while(ni != n){
// if(!may[x + (n - 2) * y])return false;
if(may[x + ni * y]) ++ni;
else return false;
}return true;
}
bool operator < (T a, T b) {
if(a.b != b.b) return a.b < b.b;
return a.a < b.a;
}
int main() {
freopen("ariprog.in", "r", stdin);
freopen("ariprog.out", "w", stdout);
cin >> n >> m;
fill(m);
int idx = 0, t = 0;
set<int>::iterator lis = list.begin();
for(int a = *lis; a < m*m*2-1; a = *(++lis)) {
for(int b = 1; b != (2*m*m - a) / (n-1) + 1; ++b) {
if(check(a, b)) {
ans[idx].a = a;
ans[idx++].b = b;
}
}
}
if(idx) {
sort(ans, ans+idx);
for(int i = 0; i != idx; ++i) {
cout << ans[i].a << " " << ans[i].b << endl;
}
}else
cout << "NONE" << endl;
return 0;
}
标签:
原文地址:http://www.cnblogs.com/liangyongrui/p/4541873.html