文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>Arithmetic Progressions

Arithmetic Progressions

时间:2011-02-23  来源:李科.YM

/*
ID: like_091
PROG: ariprog
LANG: C++
*/
#include<iostream>
#include<cmath>
#include<fstream>
using namespace std;
const int MAX = 250;
int d[MAX * MAX * 2 + 1], tem;
struct Node{
        int x, y;
}node[10001];
int cmp(const void *a, const void *b)
{
        Node *c = (Node *)a;
        Node *d = (Node *)b;
        if (c->y == d->y)
                return c->x - d->x;
        return c->y - d->y;
}
void fun(int m)
{
        for (int i = 0; i <= m; i++)
                for (int j = 0; j <= m; j++)
                        d[i * i + j * j] = 1;
}
void enqueue(int a, int b)
{
        node[tem].x = a;
        node[tem++].y = b;
}
int main()
{
        ifstream cin("ariprog.in");
        ofstream cout("ariprog.out");
        int m, n, len;
        cin>>n>>m;
        len = (int)sqrt(m * m * 2.0);
        for (int i = 0; i <= m * m * 2; i++)
                d[i] = 0;
        fun(m);
        tem = 0;
        for (int i = 0; i <= m * m * 2; i++)
                if (d[i])
                {
                        bool flag = true;
                        for (int j = 1; j <= (m * m * 2 - i) / (n - 1); j++)
                        {
                                bool flag = true;
                                for (int k = 1; k < n; k++)
                                        if (!d[k * j + i])
                                        {
                                                flag = false;
                                                break;
                                        }
                                if (flag)
                                        enqueue(i, j);
                        }
                }
        qsort(node, tem, sizeof(node[0]), cmp);
        if (!tem)cout<<"NONE"<<endl;
        for (int i = 0; i < tem; i++)
                cout<<node[i].x<<" "<<node[i].y<<endl;
        return 0;
}
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载