Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]

Codeforces Round #296 (Div. 2) A. Playing with Paper

大家好,又见面了,我是全栈君。

One day Vasya was sitting on a not so interesting Maths lesson and making an origami from a rectangular
a mm
 × 
b mm sheet of paper (
a > b). Usually the first step in making an origami is making a square piece of paper from the rectangular sheet by folding the sheet along the bisector of the right angle, and cutting the excess part.


Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]

After making a paper ship from the square piece, Vasya looked on the remaining (a - b) mm  ×  b mm strip of paper. He got the idea to use this strip of paper in the same way to make an origami, and then use the remainder (if it exists) and so on. At the moment when he is left with a square piece of paper, he will make the last ship from it and stop.

Can you determine how many ships Vasya will make during the lesson?

Input

The first line of the input contains two integers a, b (1 ≤ b < a ≤ 1012) — the sizes of the original sheet of paper.

Output

Print a single integer — the number of ships that Vasya will make.

Sample test(s)
Input
2 1

Output
2

Input
10 7

Output
6

Input
1000000000000 1

Output
1000000000000

Note

Pictures to the first and second sample test.


Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]

题意:给一a * b的板,问依照题中所给方法可以裁成多少正方形。

解析:直接递归即解。

AC代码:

#include <cstdio>
#include <cstring>
#define LL long long

LL solve(LL a, LL b){
	if(b == 1) return a;
	if(a % b == 0) return a / b;              //開始忘了考虑整除。RE on test #7
	return solve(b, a % b) + (a / b);
}

int main(){
//	freopen("in.txt", "r", stdin);
	LL a, b;
	while(scanf("%lld%lld", &a, &b)==2){
		printf("%lld\n", solve(a, b));
	}
	return 0;
}

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/116387.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • directx11是啥(polite什么意思)

    电脑爱好者朋友通常会在某款游戏最低配置要求以及某些显卡上看到有DirectX字样,一般DirectX有:Direct9.0、Direct10(简称DX9、DX10)以及时下最新的Direct11(简称DX11),很多朋友对于一些游戏中最低要求的DirectX版本很疑惑,也不知道为什么越来越多游戏都需要Direct10以上,甚至Direct11版本要求。那么DX11是什么呢?又代表着什么含…

    2022年4月14日
    79
  • 深入理解STL库_STL文件格式的工作原理

    深入理解STL库_STL文件格式的工作原理关注本人公众号,获取更多学习资料!

    2022年10月16日
    3
  • futex验证_fulvic

    futex验证_fulvic1,验证代码转载#include#include#include#include#includesem_tsem_a;void*task1();intmain(void){ intret=0; pthread_tthrd1; sem_init(&sem_a,0,1);  //createchildrenpr

    2022年9月21日
    2
  • 调用第三方接口获取数据写入数据库

    调用第三方接口获取数据写入数据库系统框架:springboot(和框架没有什么太大关系,仅记录一下)调用路径:controller→service第三方接口:http://xx.xxx.com:9905/api/list?transtime=20181017105600&token=abcdefghijklmn请求参数:{“data”:”{\”xxx\”:\”\”,\”xx\”:\”\”,\”xxxx\”:\…

    2022年6月7日
    41
  • sql server 字符串转日期_sql server 字符串替换

    sql server 字符串转日期_sql server 字符串替换提示:文章写完后,目录可以自动生成,如何生成可参考右边的帮助文档sqlserver字符串转为日期时间格式使用步骤1.引入库2.读入数据总结使用步骤1.引入库代码如下(示例):importnumpyasnpimportpandasaspdimportmatplotlib.pyplotaspltimportseabornassnsimportwarningswarnings.filterwarnings(‘ignore’)importsslssl._c

    2022年10月8日
    2
  • MATLAB中求矩阵的逆矩阵方法(2种)「建议收藏」

    MATLAB中求矩阵的逆矩阵方法(2种)「建议收藏」方法一:使用inv()函数求矩阵的逆第一步:打开matlab之后,在命令行窗口中输入a=[123;456;789],新建一个a方矩阵,如下图所示:第二步:在命令行窗口中输入inv(a),按回车键,可以看到得到了矩阵的逆,如下图所示:注意:a矩阵可逆的条件是非奇异方法二:使用a^-1格式求矩阵的逆第一步:在命令行窗口中输入a^-1,按回车键,可以得到矩阵的逆,如下图所示:其实,还可以给-1加括号“()”,a^(-1),如下图:注:a必须是方针,即行数和列数相等。…

    2022年8月21日
    10

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号