1 10 100 1000
2017-05-15 23:17
344 查看
1,10,100,1000...组成序列1101001000...,求这个序列的第N位是0还是1。
Input
Output
Input示例
Output示例
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int input[100000];
bool fun(int n)
{
int a = sqrt(2*n);
if (2*n == a*(1+a))
{
return true;
}
return false;
}
int main()
{
int n;
cin >> n;
int a;
for (int i = 0; i < n; i++)
{
cin >> a;
cout << fun(a-1) << endl;
}
return 0;
}
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000) 第2 - T + 1行:每行1个数N。(1 <= N <= 10^9)
Output
共T行,如果该位是0,输出0,如果该位是1,输出1。
Input示例
3 1 2 3
Output示例
1 1 0
#include <iostream>
#include <algorithm>
#include <string.h>
#include <math.h>
using namespace std;
int input[100000];
bool fun(int n)
{
int a = sqrt(2*n);
if (2*n == a*(1+a))
{
return true;
}
return false;
}
int main()
{
int n;
cin >> n;
int a;
for (int i = 0; i < n; i++)
{
cin >> a;
cout << fun(a-1) << endl;
}
return 0;
}
相关文章推荐
- [51NOD1087]1 10 100 1000(规律,二分)
- Timus 1209. 1, 10, 100, 1000... 根据数列推导公式
- 51nod 1087 1 10 100 1000(数学问题)
- 马化腾:用户体验的10/100/1000法则.
- timus 1209. 1, 10, 100, 1000... URAL 解题报告
- 问题 : 1 10 100 1000
- 51nod 1087 1 10 100 1000
- ural 1209. 1,10,100,1000.....
- 小技巧(四)分离字符串string str="(1,10,100,1000,10000,)";
- 51nod 1087 1 10 100 1000
- Cisco Catalyst 6500系列10/100和10/100/1000以太网接口卡
- 51Nod-1087 1 10 100 1000【模拟】
- 51Nod 1087 1 10 100 1000 | 数学
- URAL 1209. 1, 10, 100, 1000... (规律 + 二分)
- 51Nod-1087 1 10 100 1000
- 1, 10, 100, 1000...
- ural 1209. 1, 10, 100, 1000... 二分
- 1087 1 10 100 1000
- (beginner problems) ural 1209 1, 10, 100, 1000...
- 51nod--1087 1 10 100 1000