KazaQ’s Socks
Description
KazaQ wears socks everyday.
At the beginning, he has n pairs of socks numbered from 1 to n in his closets.
Every morning, he puts on a pair of socks which has the smallest number in the closets.
Every evening, he puts this pair of socks in the basket. If there are n−1 pairs of socks in the basket now, lazy KazaQ has to wash them. These socks will be put in the closets again in tomorrow evening.
KazaQ would like to know which pair of socks he should wear on the k-th day.
Input
The input consists of multiple test cases. (about 2000)
For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018).
Output
For each test case, output “Case #x: y” in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
Sample Input
3 7
3 6
4 9
Sample Output
Case #1: 3
Case #2: 1
Case #3: 2
Hint
题意
KazaQ每天穿袜子 一开始,他的衣柜里有n对袜子从1到n。 每天早晨,他穿上一双袜子,衣柜里数量最少。 每天晚上,他把这双袜子放在篮子里。 如果篮子里有n-1对袜子,懒惰的KazaQ就要洗了。 这些袜子将在明天晚上再次放在衣橱里。 KazaQ想知道他在第k天应该穿什么袜子
题解:
找两组规律就出来的 多校签到题2/1
AC代码
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int main()
{
int res = 0;
LL n, k;
while(~scanf("%lld%lld",&n,&k)) {
printf("Case #%d: ",++res);
if(k <= n) printf("%lld\n",k);
else {
k -= n;
k %= (2*(n-1));
if(k == 0) {
printf("%lld\n",n);
}
else {
if(k>=1 && k<=n-1)
printf("%lld\n",k);
else
printf("%lld\n",k+1-n);
}
}
}
return 0;
}