/*
    ID:chenjiong
    PROG:ariprog
    LANG:C++
*/

#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

const int MAXN = 250;

typedef struct {
    int a;
    int d;
}ARIPROG;

bool is_bisquare[2 * MAXN * MAXN + 1];
int bisquare[( MAXN + 1 ) * ( MAXN + 1 )];
int cnt = 0;
int N,M;
int u_bound;
ARIPROG ans[10000];
int num = 0;

void init()
{
    memset(is_bisquare,0,sizeof(is_bisquare));

    u_bound = 2 * M * M;

    int i,j;
    for ( i = 0; i <= M; i++)
    {
        for ( j = 0; j <= M; j++)
        {
            int t = i * i + j * j;
            if ( !is_bisquare[t] )
            {
                is_bisquare[t] = true;
                bisquare[cnt++] = t;
            }
        }
    }
    sort(bisquare,bisquare + cnt);
}

bool is_ok(int a,int d)
{
    if ( a + ( N - 1 ) * d > u_bound )
        return false;
    int i;
    for ( i = 0; i < N; i++)
    {
        if ( !is_bisquare[a + i * d] || a + i * d > u_bound )
            return false;
    }
    return true;
}
                
void search()
{
    int i,j;
    for ( i = 0; i < cnt; i++)
    {
        for ( j = i + 1; j < cnt; j++)
        {
            int a = bisquare[i];
            int d = bisquare[j] - bisquare[i];
            if ( is_ok(a,d) )
            {
                ans[num].a = a;
                ans[num].d = d;
                num++;
            }
        }
    }
}

bool cmp(const ARIPROG& a,const ARIPROG& b)
{
    if ( a.d < b.d )
        return true;
    else if ( a.d == b.d )
        return a.a < b.a;
    else
        return false;
}

int main()
{
    freopen("ariprog.in","r",stdin);
    freopen("ariprog.out","w",stdout);

    scanf("%d%d",&N,&M);

    init();
    search();

    if ( num == 0 )
        printf("NONE\n");
    else
    {
        sort(ans,ans + num,cmp);
        for (int i = 0; i < num; i++)
            printf("%d %d\n",ans[i].a,ans[i].d);
    }

    return 0;
}
                

 

posted on 2012-10-25 19:51  Sinker  阅读(165)  评论(0编辑  收藏  举报