1 10 100 1000

  1. 1,10,100,1000...组成序列1101001000...,求这个序列的第N位是0还是1。
    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

  2. #include <iostream>  
  3. #include <cstdio>  
  4. #include <cmath>  
  5.   
  6. using namespace std;  
  7.   
  8. int main(int argc, const char * argv[])  
  9. {  
  10.     int T;  
  11.     int N;  
  12.   
  13.     cin >> T;  
  14.     while (T--)  
  15.     {  
  16.         scanf("%d", &N);  
  17.         double m = sqrt((N - 1) * 2);  
  18.         if ((int)m * (int)(m + 1) == (N - 1) * 2)  
  19.         {  
  20.             printf("1\n");  
  21.         }  
  22.         else  
  23.         {  
  24.             printf("0\n");  
  25.         }  
  26.     }  
  27.   
  28.     return 0;  
  29. }

猜你喜欢

转载自blog.csdn.net/sinat_40948489/article/details/80020189