KazaQ's Socks
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 338 Accepted Submission(s): 212
Sample Input
3 7 3 6 4 9
Sample Output
Case #1: 3 Case #2: 1 Case #3: 2
Source
分析:
然后分别去判断即可!详细请看代码。
下面给出AC代码:
1 #include <bits/stdc++.h> 2 using namespace std; 3 typedef long long ll; 4 int main() 5 { 6 ll n,m; 7 ll p=1; 8 while(scanf("%lld%lld",&n,&m)!=EOF) 9 { 10 printf("Case #%lld: ",p++); 11 if(m<=n) 12 { 13 printf("%lld ",m); 14 continue; 15 } 16 ll c=m-n; 17 if(c%(2*(n-1))==0) 18 { 19 printf("%lld ",n); 20 continue; 21 } 22 if(c%(2*(n-1))<=n-1) 23 printf("%lld ",c%(2*(n-1))); 24 else 25 { 26 ll k=c%(2*(n-1))%(n-1); 27 printf("%lld ",k); 28 } 29 } 30 return 0; 31 }