Problem Description
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.

 
Input
The input consists of multiple test cases. (about 2000)

For each case, there is a line contains two numbers n,k (2≤n≤109,1≤k≤1018).

 
Output
For each test case, output "Case #x: y" in one line (without quotes), where x indicates the case number starting from 1 and y denotes the answer of corresponding case.
 
Sample Input
3 7
3 6
4 9
 
Sample Output
Case #1: 3
Case #2: 1
Case #3: 2
题意:自己看看吧,很简单
解法:
1 理解题意后,知道应该是找循环节,于是写了1 2 3 和 1 2 3 4发现是1 2,1 3和1 2 3,1 2 4这样顺序
2 然后分情况讨论
 #include<bits/stdc++.h>
typedef long long LL;
typedef unsigned long long ULL;
using namespace std;
const int maxn=2e5+;
int main(){
long long n,k;
long long num=;
while(cin>>n>>k){
printf("Case #%lld: ",num++);
if(k<=n){
cout<<k<<endl;
}else{
k-=n;
long long pos=k/(n-);
long long ans=k%(n-);
if(ans){
cout<<ans<<endl;
}else{
if(pos%){
cout<<n-<<endl;
}else{
cout<<n<<endl;
}
}
}
}
return ;
}

2017 Multi-University Training Contest - Team 1 KazaQ's Socks的更多相关文章

  1. 2017 Multi-University Training Contest - Team 1 1011&&HDU 6043 KazaQ's Socks【规律题,数学,水】

    KazaQ's Socks Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  2. 2017 Multi-University Training Contest - Team 9 1005&&HDU 6165 FFF at Valentine【强联通缩点+拓扑排序】

    FFF at Valentine Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  3. 2017 Multi-University Training Contest - Team 9 1004&&HDU 6164 Dying Light【数学+模拟】

    Dying Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Tot ...

  4. 2017 Multi-University Training Contest - Team 9 1003&&HDU 6163 CSGO【计算几何】

    CSGO Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  5. 2017 Multi-University Training Contest - Team 9 1002&&HDU 6162 Ch’s gift【树链部分+线段树】

    Ch’s gift Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total S ...

  6. 2017 Multi-University Training Contest - Team 9 1001&&HDU 6161 Big binary tree【树形dp+hash】

    Big binary tree Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. 2017 Multi-University Training Contest - Team 1 1003&&HDU 6035 Colorful Tree【树形dp】

    Colorful Tree Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

  8. 2017 Multi-University Training Contest - Team 1 1006&&HDU 6038 Function【DFS+数论】

    Function Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  9. 2017 Multi-University Training Contest - Team 1 1002&&HDU 6034 Balala Power!【字符串,贪心+排序】

    Balala Power! Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)T ...

随机推荐

  1. 棋盘覆盖问题 (粉书 P230 【递归】** )

    转载自:http://blog.csdn.net/akof1314/article/details/5423608  (赞) 在一个 2^k * 2^k 个方格组成的棋盘中,若恰有一个方格与其它方格不 ...

  2. Ubuntu下codeblocks编译器程序执行对话框内能进行粘贴编辑操作的指令

    如这个:  gnome-terminal  -t $TITLE -x

  3. Appium——Error while obtaining UI hierarchy XML file:com.android.ddmlib.SyncException:

    使用uiautomatorviewer查看页面元素时报这个错误,解决办法 cmd: adb root ok  解决

  4. XML中CDATA和#PCDATA的区别

    在XML文档中, 能看到“CDATA"的地方有三处: 1)在DTD中,指定标签中某个属性的类型为字符型时,使用CDATA.因为XML解析器会去分析这段字符内容,因而里面如果需要使用>, ...

  5. PHP编写网页BS结构计算器

    利用PHP和Html + javascript 编写一个简单的网页计算器程序,可以根据这种有趣的开发构架出更加有趣的网页.​1. [代码]PHP计算器    <html><head& ...

  6. smarty模板引擎基础(二)

    smarty模板引擎所需文件夹共可分为存放页面缓存的(cache).存放配置文件的(configs).存放模板扩充插件的(plugins).存放模板文件的(templates).存放编译后的模板文件的 ...

  7. BZOJ_2989_数列&&BZOJ_4170_极光_KDTree

    BZOJ_2989_数列&&BZOJ_4170_极光_KDTree Description "若是万一琪露诺(俗称rhl)进行攻击,什么都好,冷静地回答她的问题来吸引她.对方 ...

  8. [Codeforces 877E] Danil and a Part-time Job

    [题目链接] https://codeforces.com/contest/877/problem/E [算法] 首先求出这棵树的DFS序 一棵子树的DFS序为连续的一段 , 根据这个性质 , 用线段 ...

  9. 解决Exception:Could not open Hibernate Session for transaction; nested exception is java.lang.NoClassDefFoundError: org/hibernate/engine/transaction/spi/TransactionContext

    原因是配置文件中 <bean id="transactionManager" class="org.springframework.orm.hibernate4.H ...

  10. WinDbg 调试工具的使用

    概述 项目接近尾声了,可是在运行时会有memory leak(内存泄露) bug.产品在运行一天后,内存增长致1.4G,而我们产品的初始内存才有70M,问题很严重,决定采用WinDbg工具来分析代码问 ...