Problem Description
It is the king's birthday before the military parade . The ministers prepared a rectangle cake of size n×m(1≤n,m≤10000) . The king plans to cut the cake himself. But he has a strange habit of cutting cakes. Each time, he will cut the rectangle cake into two pieces, one of which should be a square cake.. Since he loves squares , he will cut the biggest square cake. He will continue to do that until all the pieces are square. Now can you tell him how many pieces he can get when he finishes.
 
Input
The first line contains a number T(T≤1000), the number of the testcases.

For each testcase, the first line and the only line contains two positive numbers n,m(1≤n,m≤10000).

 
Output
For each testcase, print a single number as the answer.
 
Sample Input
2
2 3
2 5
 
Sample Output
3
4

hint:
For the first testcase you can divide the into one cake of $2\times2$ , 2 cakes of $1\times 1$

 
Source
 

切正方形蛋糕,两条边轮流互减

 #include <iostream>
#include <cstdio>
using namespace std;
#define LL long long
int m,n,t;
LL ans;
int main(){
scanf("%d",&t);
while(t--){
scanf("%d%d",&m,&n);
ans=;
while(m>&&n>){
if(m>n) swap(m,n);
n-=m;
ans++;
}
cout<<ans<<endl;
}
}

BestCoder Round #75 1001 - King's Cake的更多相关文章

  1. BestCoder Round #75 1003 - King's Order

    国王演讲后士气大增,但此时战争还没有结束,国王时不时要下发命令. 由于国王的口吃并没有治愈,所以传令中可能出现:“让第三军-军-军,到前线去” 这样的命令.由于大洋国在军队中安插了间谍 , 战事紧急, ...

  2. BestCoder Round #75 1002 - King's Phone

    问题描述 阅兵式上,国王见到了很多新奇东西,包括一台安卓手机.他很快对手机的图形解锁产生了兴趣. 解锁界面是一个 3×33 \times 33×3 的正方形点阵,第一行的三个点标号 1,2,31, 2 ...

  3. hdu 5643 BestCoder Round #75

    King's Game  Accepts: 249  Submissions: 671  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: 6 ...

  4. hdu 5641 BestCoder Round #75

    King's Phone  Accepts: 310  Submissions: 2980  Time Limit: 2000/1000 MS (Java/Others)  Memory Limit: ...

  5. 贪心 BestCoder Round #39 1001 Delete

    题目传送门 /* 贪心水题:找出出现次数>1的次数和res,如果要减去的比res小,那么总的不同的数字tot不会少: 否则再在tot里减去多余的即为答案 用set容器也可以做,思路一样 */ # ...

  6. ACM学习历程—BestCoder Round #75

    1001:King's Cake(数论) http://acm.hdu.edu.cn/showproblem.php?pid=5640 这题有点辗转相除的意思.基本没有什么坑点. 代码: #inclu ...

  7. 暴力 BestCoder Round #41 1001 ZCC loves straight flush

    题目传送门 /* m数组记录出现的花色和数值,按照数值每5个搜索,看看有几个已满足,剩下 5 - cnt需要替换 ╰· */ #include <cstdio> #include < ...

  8. 暴力 BestCoder Round #46 1001 YJC tricks time

    题目传送门 /* 暴力:模拟枚举每一个时间的度数 详细解释:http://blog.csdn.net/enjoying_science/article/details/46759085 期末考结束第一 ...

  9. 字符串处理 BestCoder Round #43 1001 pog loves szh I

    题目传送门 /* 字符串处理:是一道水题,但是WA了3次,要注意是没有加'\0'的字符串不要用%s输出,否则在多组测试时输出多余的字符 */ #include <cstdio> #incl ...

随机推荐

  1. Sublime Text 添加到右键菜单 带菜单图标

    1.打开 regedit 2.找到节点 HKEY_CLASSSES_ROOT -> * -> Shell 3.右键选择新建“ 项 ” 这个项的名字将作为右键菜单的菜单名称,我用的“ Sub ...

  2. a:hover span 隐藏/显示 问题

    :hover是我们在CSS设计中最常运用的伪类之一,许多绚丽效果的实现离不开伪类:hover,比如我们常见的纯CSS菜单.相册效果等等. 或许用了这么久的伪类:hover,还有部分朋友还不完全了解ho ...

  3. Android app去应用市场评分功能

    因为android市场很多,去各个应用市场评分的功能却不是很难实现. private void gotoRate(){ Uri uri = Uri.parse("market://detai ...

  4. 下拉菜单中的Option对象

    1.创建Option对象 1.1 var optionEle1 = document.createElement('option'); 1.2 var optionEle2 = new Option( ...

  5. .Net中如何使用MySql连接池

    提供一份官方的译文.翻译也挺辛苦的!! 6.4 Using Connector/Net with Connection Pooling 6.4在Connector/Net中使用连接池 The Conn ...

  6. sql 事务和回滚

    (1) set ANSI_NULLS ON --见图1 set QUOTED_IDENTIFIER ON go ALTER proc [dbo].[procname] as begin begin t ...

  7. I - Long Distance Racing(第二季水)

    Description Bessie is training for her next race by running on a path that includes hills so that sh ...

  8. [转]C++实现系统服务暂停、停止、启动

    /* 名称:系统服务管理 语言:C++ 介绍:对Windows系统服务的状态获取,服务暂停,开启,停止操作代码 */ void CStartServiceDlg::OnBnClickedButton1 ...

  9. 使用phpExcel导入Excel进入Mysql数据库

    1.http://phpexcel.codeplex.com/下载phpExcel 2. <? require_once 'PHPExcel.php'; require_once 'PHPExc ...

  10. inline 间距

    今天看了内联元素的间距: http://blog.csdn.net/hedong37518585/article/details/6657853