ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1209. 1, 10, 100, 1000...

ac (cpp)
Posted by lhyx1990 26 Jan 2014 16:59

#include <iostream>
#include <math.h>

using namespace std;

bool isOne(int n);
int main(int argc, const char * argv[])
{

    int n;
    cin >> n;

    int *nums = new int[n];
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        nums[i] = k;
    }

    for (int i = 0; i < n; i++) {
        int index = nums[i] - 1;
        if (isOne(index)) cout << 1 << " ";
        else cout << 0 << " ";
    }
    delete [] nums;
}

bool isOne(int n) {

    double ans = (sqrt((double) 8 * n + 1) - 1) / 2;
    int r = (int) ans;
    if (r * (r + 1) / 2 == n) return true;
    return false;
}