51Nod 1087 1 10 100 1000
如果将第二位看成第一位,那么 k * (k+1) / 2都是1,k >= 1,那么其他位都是 0
所以如果n-1=k*(k+1)/2 (n>1),则该位就是1
1 #include<iostream> 2 #include<algorithm> 3 #include<cmath> 4 using namespace std; 5 6 int main() 7 { 8 std::ios::sync_with_stdio(false); 9 int t, n; 10 cin >> t; 11 while (t--){ 12 cin >> n; 13 if (n == 1){ cout << "1" << endl; continue; } 14 int k = sqrt(2 * (n - 1));//判断2*n=k*(k+1) 15 for (int i = k;; i++){ 16 if (i*(i + 1) == 2 * (n - 1)){ 17 cout << "1" << endl; 18 break; 19 } 20 if (i*(i + 1) > 2 * (n - 1)){ 21 cout << "0" << endl; 22 break; 23 } 24 } 25 26 } 27 return 0; 28 }