|
|
back to boardac (cpp) #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; } |
|
|