URAL 1209 - 1, 10, 100, 1000... (简单推导)
题意
判断第N个是不是1
思路
发现在$1 + (1 + x) * x / 2$上的都是1,然后只要判断这个位置即可。
代码
#include <cstdio>
#include <stack>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <functional>
#include <cstring>
#include <algorithm>
#include <cctype>
#include <string>
#include <map>
#include <cmath>
#define LL long long
#define SZ(x) (int)x.size()
#define Lowbit(x) ((x) & (-x))
#define MP(a, b) make_pair(a, b)
#define MS(arr, num) memset(arr, num, sizeof(arr))
#define PB push_back
#define F first
#define S second
#define ROP freopen("input.txt", "r", stdin);
#define MID(a, b) (a + ((b - a) >> 1))
#define LC rt << 1, l, mid
#define RC rt << 1|1, mid + 1, r
#define LRT rt << 1
#define RRT rt << 1|1
#define BitCount(x) __builtin_popcount(x)
const double PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
using namespace std;
const int MAXN = 10000 + 10;
const int MOD = 1e9 + 7;
typedef pair<int, int> pii;
typedef vector<int>::iterator viti;
typedef vector<pii>::iterator vitii;
int main()
{
int T, i, j, n;
scanf("%d", &T);
while (T--)
{
scanf("%d", &n);
n--;
LL k = 2ll * n;
LL l = (int)(sqrt(1 + 4 * k) / 2);
LL r = l + 1;
if ((1 + l) * l == k || (1 + r) * r == k) printf("1 ");
else printf("0 ");
puts("");
}
}