KazaQ's Socks

来源:互联网 发布:gtp手机吉他谱软件 编辑:程序博客网 时间:2024/05/29 10:07
KazaQ wears socks everyday. 

At the beginning, he has nn pairs of socks numbered from 11 to nn 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 n1n−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 kk-th day.
Input
The input consists of multiple test cases. (about 20002000

For each case, there is a line contains two numbers n,kn,k (2n109,1k1018)(2≤n≤109,1≤k≤1018).
Output
For each test case, output " Case #xxyy" in one line (without quotes), where xxindicates the case number starting from 11 and yy denotes the answer of corresponding case.
Sample Input
3 73 6

4 9

#include <cstdio>#include <algorithm>using namespace std;int main(){    long long t=1,n,k,a[2];    while(~scanf("%lld %lld",&n,&k))    {        a[1]=n-1,a[0]=n;        if(k<=n)        {            printf("Case #%lld: %lld\n",t++,k);        }        else        {            k-=n;            if(k%(n-1)==0)            {                long long num=k/(n-1);                printf("Case #%lld: %lld\n",t++,a[num%2]);            }            else                printf("Case #%lld: %lld\n",t++,k%(n-1));        }    }    return 0;}


原创粉丝点击