51Nod 1087 1 10 100 1000

打表,把所有(1)出现的位置存起来。

unordered_set<int> S;

void init()
{
    for(int i=1,d=1;i<=1e9;)
    {
        S.insert(i);
        i+=d;
        d++;
    }
}

int main()
{
    init();

    int T;
    cin>>T;
    while(T--)
    {
        int x;
        cin>>x;
        if(S.count(x)) cout<<1<<endl;
        else cout<<0<<endl;
    }
    //system("pause");
    return 0;
}
原文地址:https://www.cnblogs.com/fxh0707/p/14618593.html