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. MQTT 测试工具介绍

    eclipse paho 下载地址为: https://repo.eclipse.org/content/repositories/paho-releases/org/eclipse/paho/org ...

  2. [Maven实战](9)传递性依赖

    了解Spring的朋友都知道.创建一个Spring Framework项目都须要依赖什么样的Jar包.假设不使用Maven,那么在项目中就须要手动下载相关的依赖.因为Spring Framework又 ...

  3. Cocos2d-X中的粒子

    Cocos2d-x引擎提供了强大的type=cocos2d-x&url=/doc/cocos-docs-master/manual/framework/native/v3/particle-s ...

  4. Android Studio 工程的 .gitignore

    新建一个 Android Studio 工程时会默认建立两个 .gitignore 文件 .gitignore *.iml .gradle /local.properties /.idea/works ...

  5. 简化Android的startActivityForResult调用

    一个是解决在onActivityResult 中判断requestCode的问题,第二个是让调用代码的地方就知道我是如何处理对方activity 的返回的. 首先我们有一个ResultActivity ...

  6. 在JS中将JSON的字符串解析成JSON数据格式

    使用eval函数来解析 <script> var data="{root: [{name:'1',value:'0'},{name:'6101',value:'北京市'},{na ...

  7. Sping框架概述

    一.什么是spring框架 spring是J2EE应用程序框架,是轻量级的IoC和AOP的容器框架,主要是针对javaBean的生命周期进行管理的轻量级容器,可以单独使用,也可以和Struts框架,i ...

  8. 九度OJ 1132:与7无关的数 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1619 解决:1037 题目描述: 一个正整数,如果它能被7整除,或者它的十进制表示法中某个位数上的数字为7, 则称其为与7相关的数.现求所 ...

  9. mysql user password plugin

    caching_sha2_passwordcaching_sha2_passwordcaching_sha2_passwordcaching_sha2_passwordcaching_sha2_pas ...

  10. 动态绑定允许我们在程序运行的过程中动态给class加上功能,这在静态语言中很难实现

    https://www.liaoxuefeng.com/wiki/ # 正常情况下,当我们定义了一个class,创建了一个class的实例后,我们可以给该实例绑定任何属性和方法, # 这就是动态语言的 ...