题解:P11310 无穷的迭代器
pengchengen
·
·
题解
一道数学题
首先分类讨论。
当 k=0 时:
`cout << "No!\n";`
---
当 $k$ 是奇数时:
$\lceil r \rceil = k + 1,\therefore \lceil r \rceil$ 是偶数。
所以输出 $1$ 即可。
`cout << 1 << '\n';`
---
当 $k$ 是非零偶数时:
我们要使 $\lceil r \rceil \bmod 2 = 0$。
$\because$ 当 $\lceil r \rceil$ 是奇数时,$r \cdot \lceil r \rceil=p + \dfrac{1}{2},
---
**最后附上代码:**
```cpp
#include<bits/stdc++.h>
using namespace std;
int T;
long long x;
double a;
long long u;
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
cin>>T;
while(T--){
cin>>x;
if(x==0){
cout<<"NO!\n";
continue;
}
if(x%2) cout<<1<<'\n';
else{
int s=0;
while(x){
if(x%2) break;
s++;
x/=2;
}
cout<<s+1<<'\n';
}
}
return 0;
}
```