描述
题解
找规律,查找数列中1的通式。
(0+1+2+…n)+1==N
(o+n)*(n+1)/2+1==N
n*(n+1)==(N-1)*2
(N-1)*2=m*m
n
代码
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(int argc, const char * argv[])
{
int T;
int N;
cin >> T;
while (T--)
{
scanf("%d", &N);
double m = sqrt((N - 1) * 2);
if ((int)m * (int)(m + 1) == (N - 1) * 2)
{
printf("1\n");
}
else
{
printf("0\n");
}
}
return 0;
}

本文介绍了一道ACM竞赛中的模版题目及其解决方法,通过寻找数列中1的通式来解决问题,并给出了具体的数学推导过程及C++实现代码。
751

被折叠的 条评论
为什么被折叠?



