您的位置:首页 > 其它

KazaQ's Socks HDU - 6043

2017-10-31 22:17 302 查看
KazaQ wears socks everyday. At the beginning, he has nn pairsof socks numbered from 11 to nn inhis 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−1n−1 pairsof 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-thday.InputThe input consists of multiple test cases. (about 20002000) For each case, there is a line contains two numbers n,kn,k (2≤n≤109,1≤k≤1018)(2≤n≤109,1≤k≤1018).OutputFor each test case, output " Case #xx: yy"in one line (without quotes), where xx indicatesthe case number starting from 11 and yydenotesthe answer of corresponding case.Sample Input
3 7
3 6
4 9
Sample Output
Case #1: 3
Case #2: 1
Case #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;}

                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: