51NOD 1087 1 10 100 1000

http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1087

暴力大法

#include<bits/stdc++.h>
using namespace std;
map <int,int>s;

void solve()
{
    int i=1,k=1;
    while (i<=1e9)
    {
        s[i] = 1;
        i+=k;
        k++;
    }
}

int main ()
{
    int t,n;
    solve();scanf("%d",&t);
    while (t--){
        scanf("%d",&n);
        printf("%d\n",s[n]);
    }

}

 

 

百度 an - an-1 = n-1 就可以知道通项公式

然后 用公式算

#include<bits/stdc++.h>
using namespace std;

int main ()
{
    int t,n;
    scanf("%d",&t);
    while (t--){
        scanf("%d",&n);
        int t = sqrt(2*n-2);
        if(t * (t+1) == 2*n-2)
            printf("1\n");
        else
            printf("0\n");
    }
}

 

posted @ 2017-08-15 15:19  Draymonder  阅读(183)  评论(0编辑  收藏  举报