思路
分为两种情况
-
没有重叠:因为拨动 次,所以范围应该是 。
- 而 是奇数时,顺时针 个,逆时针 个,总共 个。
- 是偶数时,顺时针 个,逆时针 个,总共 个。
- 所以一共 个。
-
已经重叠: 因为它是一个环,那肯定有重叠的时候。
- 当 为奇数时,增加和减少会错开,所以只要 大于等于 时,就输出 就行了。
- 当 为偶数时,只要 达到 一半就行了,因为 的个数是偶数,到一半就重叠了。
最后答案比较 和 或 就行了。
Code
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int t;
cin>>t;
while (t--)
{
int n,k;
cin>>n>>k;
int ans=(n%2)?n:n/2;
cout<<min(k+1,ans)<<"\n";
}
return 0;
}