ZOJ 3935 2016(水题)

题目:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=115189#problem/L

代码:

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

using namespace std;

int judge1(int x)
{
    //printf("%d\n",(int)sqrt(2*x));
    int t=(int)sqrt(2*x);
    if(t*(t+1)==x*2)
        return 1;
    return 0;
}

int judge2(int x)
{
    int t=(int)sqrt(1+8*x);
    if(t*t==1+8*x)
    {
        if((1+t)%4==0)
        {
            return 1;
        }
    }
    return 0;
}
int main()
{
    for(int i=2016; i<=990528; i++)
    {
        if((i%400==0)||(i%4==0&&i%100!=0))
        {
            if(judge1(i))
            {
                if(judge2(i))
                {
                    printf("%d\n",i);
                }
            }
        }
    }
}


你可能感兴趣的:(ZOJ 3935 2016(水题))