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;
}
}

最新文章

  1. 让所有浏览器包括IE6即支持最大宽度又支持最小宽度。
  2. 模拟实现兼容低版本IE浏览器的原生bind()函数功能
  3. 调用支付宝接口Android客户端没有支付宝APP的情况下解决无法调用支付宝页面的问题
  4. Qt4.8 移植(超详细Configure的参数)
  5. IE CSS Bug 系列
  6. struts2——配置struts.xml文件
  7. jvm系列 (五) ---类的加载机制
  8. mysql varchar vs oracle varchar2
  9. href的理解
  10. nodejs的某些api~(二)crypto加密模块
  11. python使用MySQLdb实现连接数据库Mysql
  12. db2安装
  13. Python3学习之路~5.3 random模块
  14. java设计模式-Observe
  15. JavaScript的进阶篇
  16. mybatis-spring集成:配置多数据库源中遇到的问题
  17. HUE配置文件hue.ini 的mapred_clusters模块详解(图文详解)(分HA集群和非HA集群)
  18. 用python批量执行VBA代码
  19. 流行的FPGA的上电复位
  20. openresty websocket 使用

热门文章

  1. JS Encoding and Decoding
  2. Java Junit4测试功能
  3. Reverse Linked List II java
  4. C#中Spli、正则表达式分解字符串详解
  5. java 短信发送例子 tdy
  6. jQuery的类数组对象结构
  7. Joomla JEvents 组件
  8. twisted 使用
  9. Holding Bin-Laden Captive!(hdoj1085)代码并未完全看懂
  10. SQL Server 引起磁盘IO的原因