KazaQ's Socks HDU

来源:互联网 发布:mac版ps存储快捷键 编辑:程序博客网 时间:2024/06/05 16:52
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 xx indicates the case number starting from 11 and yydenotes the answer of corresponding case.
Sample Input
3 73 64 9
Sample Output
Case #1: 3Case #2: 1Case #3: 2
找规律  模拟
#include <stdio.h>typedef long long ll;int main() {ll n , k , m , m1 , m2;int Case = 1;while(~scanf("%lld%lld",&n,&k)) {if(k <= n) m = k;else {m = k - n;m1 = m/(n-1);m2 = m%(n-1);if(m2) {if(m1%2) {m = m2;}else{if(m2 == n-1) m = n;else m = m2;}}else {if(m1%2) m = n-1;else m = n;}}printf("Case #%d: %d\n",Case++,m);}return 0;}


原创粉丝点击