Time Limit: 4000ms, Special Time Limit:10000ms, Memory Limit:65536KB
Total submit users: 20, Accepted users: 12
Problem 13553 : No special judgement
Problem description

Bob has learned a new magic trick that needs a very special preparation. Once he masters the trick he will be able to bring peace to the world, but if he fails, the world will be destroyed.

The preparation is performed as follows: There are two containers, initially one is empty and the other one has X marbles. Bob has a Marble Cloning Machine, it clones the marbles in the container with the larger number of marbles, then pours the new clones into the other container (e.g. if the two containers have 7 and 4 marbles, after the cloning step they will have 7 and 11 marbles). The machine does this cloning operation exactly M times. However, there is a bug in the machine, after it performs N cloning operations (N ≤ M ), it will add Y extra marbles to the container with the larger number of marbles. Then the machine will continue normally with the cloning operation exactly M - N times.

During the cloning operations, if both containers have the same number of marbles, any of them can be considered the one with the larger number of marbles.

Now, the bug in Bob’s machine is threatening to destroy the world. But his nerdy friend Alice told him that she knows how to fix it. All he has to do is to calculate the greatest common divisor of the sizes of the two containers after the cloning machine is done. Can you help Bob save the world?

Input

Your program will be tested on one or more test cases. The first line of the input will be a single integer T (1 ≤ T ≤ 1,000) representing the number of test cases. Followed by T test cases. Each test case will consist of a single line, containing 4 integers separated by a single space X , N , Y and M (1 ≤ X , Y ≤ 1,000) (0 ≤ N ≤ 70) (N ≤ M ≤ 100,000) which are the numbers as described above.

Output

For each test case print a single line containing “Case n:” (without quotes) where n is the test case number (starting from 1) followed by a space then the greatest common divisor of the sizes of the two containers after the machine is done.

Sample Input
2
4 3 6 5
5 1 15 2
Sample Output
Case 1: 2
Case 2: 5
Judge Tips
Note In the first sample test case, the number of marbles in each container will be the following after each step: (4, 0), (4, 4), (4, 8), (12, 8), (18, 8), (18, 26), (44, 26). The greatest common divisor of 44 and 26 is 2.

题意:

有两个容器,一个为空,另一个有x大理石,总共有m次操作,每次操作可以从两容器较大的一个中克隆所有大理石并加到另一个容器中,执行完第n次操作后要在较大的容器中额外加入y大理石,再继续剩余m-n操作。求最终两容器中个数的最大公约数。

附AC代码:

 #include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
using namespace std; typedef __int64 ll; ll t,x,n,y,m;
ll a,b; ll GDC(ll a,ll b){
return (b>)?GDC(b,a%b):a;
} int main(){
while(cin>>t&&t){
int ans=;
while(t--){
cin>>x>>n>>y>>m;
a=;
b=x;
for(int i=;i<=n;i++){
if(b>a){
a+=b;
}
else{
b+=a;
}
} if(a>=b){
a+=y;
}
else{
b+=y;
} ll sum;
if(a>b){
sum=GDC(a,b);
}
else{
sum=GDC(b,a);
}
printf("Case %d: %I64d\n",ans,sum);
ans++;
}
}
return ;
}

Game of Peace的更多相关文章

  1. MYSQL分页存储过程及事务处理--转自peace

    MYSQL的分页过程,和事务处理的一个测试过程. /* --名称:MYSQL版查询分页存储过程 by peace 2013-8-14 --输入参数:@fields -- 要查询的字段用逗号隔开 --输 ...

  2. Find the peace with yourself

    The purpose of being mature is to find the real calm and peace with yourself. Or you can say the tur ...

  3. The Real Meaning of Peace

    The Real Meaning of Peace There once was a king who offered a prize to the artist who would paint th ...

  4. UX设计案例研究:建立更好的用户体验(重新设计Air Peace Airline网站)

    以下内容由Mockplus团队翻译整理,仅供学习交流,Mockplus是更快更简单的原型设计工具. 坐飞机旅行总是能给人带来很棒的体验,但我认为应该考虑预订航班时给用户带来的压力.在如今的数字世界,我 ...

  5. HDU 5434 Peace small elephant 状压dp+矩阵快速幂

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5434 Peace small elephant  Accepts: 38  Submissions: ...

  6. 2018.09.28 hdu5434 Peace small elephant(状压dp+矩阵快速幂)

    传送门 看到n的范围的时候吓了一跳,然后发现可以矩阵快速幂优化. 我们用类似于状压dp的方法构造(1(1(1<<m)∗(1m)*(1m)∗(1<<m)m)m)大小的矩阵. 然后 ...

  7. Crystal Clear Applied: The Seven Properties of Running an Agile Project (转载)

    作者Alistair Cockburn, Crystal Clear的7个成功要素,写得挺好. 敏捷方法的关注点,大家可以参考,太激动所以转载了. 原文:http://www.informit.com ...

  8. MongoDB学习笔记二—Shell操作

    数据类型 MongoDB在保留JSON基本键/值对特性的基础上,添加了其他一些数据类型. null null用于表示空值或者不存在的字段:{“x”:null} 布尔型 布尔类型有两个值true和fal ...

  9. Peter Hessler和他的中国三部曲(上)

    大约一年前,我从<英语铺子>栏目知道了Peter Hessler这位作家.主播分享了她的一些读后感和印象深刻的片段,当然主要是主播的声音太甜了,让我对这位美国作家留下了深刻的印象. Pet ...

随机推荐

  1. kubernetes调度之 PriorityClass

    系列目录 kubernetes支持多种资源调度模式,前面讲过简单的基于nodeName和nodeSelector的服务器资源调度,我们称之为用户绑定策略,下面简要描述基于PriorityClass的同 ...

  2. kubernetes之故障排查和节点维护(二)

    系列目录 案例现场: 测试环境集群本来正常,突然间歇性地出现服务不能正常访问,过一会儿刷新页面又可以正常访问了.进入到服务所在的pod查看输出日志并没有发现异常.使用kubectl get node命 ...

  3. canvas转盘抽奖的实现(二)

    本篇是<canvas转盘抽奖的实现(一)>的另一种实现方法,主要通过css3的transform以及transition过渡来实现.     // ' + r + '等奖'; } draw ...

  4. MySQL 数据类型转换

    版权个人所有,欢迎转载如转载请说明出处.(东北大亨) http://www.cnblogs.com/northeastTycoon/p/5505523.html 网络越来越达到所以带来的好处不容置疑. ...

  5. Problem binding to [bigdata-server-01:9000] java.net.BindException: Cannot assign requested address;

    If the port is "0", then the OS is looking for any free port -so the port-in-use and port- ...

  6. cenos 6.5 安装apache 2.4.28出现种问题

    编译出错 configure: error: APR-util not found. Please read the documentation 解决办法 wget http://apache.fre ...

  7. Android笔记之Snackbar的基本使用

    使用Snackbar之前,须导入com.android.support:design 使用示例 package com.bu_ish.snackbar_test; import android.gra ...

  8. Javascript - ERR_CONTENT_LENGTH_MISMATCH

    不知道做了什么,有两天没有跑vue项目啦,今天突然出现加载脚本的时候出现 ERR_CONTENT_LENGTH_MISMATCH这个错误, 所以我去搜索了一下  找到如下答案  http://stac ...

  9. int 转十六进制

    //使用1字节就可以表示bpublic static String numToHex8(int b) {        return String.format("%02x", b ...

  10. 基于BASYS2的VHDL程序与烧写——按键消抖程序

    请尊重作者版权,转载请注明源地址http://www.cnblogs.com/connorzx/p/3548364.html 按键在按下的过程中通常会产生一段时间的抖动,为了消除这种抖动,一般采取两种 ...