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