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.
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.
For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018) .
3 7 3 6 4 9
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; }