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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 完美解决:针对tensorflow中,tf.logging.set_verbosity(tf.logging.ERROR)问题。

    完美解决:针对tensorflow中,tf.logging.set_verbosity(tf.logging.ERROR)问题。tf.logging.set_verbosity(tf.logging.ERROR)代码作用:让tensorflow只讲错误信息进行记录。因为Tensorflow2.0移除了一些API,其中就包括logging属性。所以如果你用tensorflow2.0的话,请参考下文解决。解决方法:将此代码更换为:tf.compat.v1.logging.set_verbosity(tf.compat…

    2025年6月14日
    0
  • mybatis 为什么要设置jdbcType

    mybatis 为什么要设置jdbcType以前没注意过这个问题,用ibatis的时候从来没有设置过jdbcType。ibatis也不会出现这个问题。学习了——————————————————————————————————————————————转载自:http://makemyownlife.iteye.com/blog/1610021前天遇到一个问题异常显示如下: 引用Exceptioninthr

    2022年10月20日
    0
  • 汇编移位指令复习「建议收藏」

    汇编移位指令复习「建议收藏」前言吐槽一下下,汇编的指令真的好多呀,学了这么多可是记住的却没几个,所以写下这篇文章加深对汇编移位指令的理解和记忆文章目录前言1、逻辑移位指令逻辑左移SHL逻辑右移SHR2、算术移位指令算数左移SAL算术右移SAR3、循环移位指令循环左移ROL循环右移ROR4、注意点1、逻辑移位指令逻辑移位指令适用于带符号数运算逻辑左移SHL指令格式:SHLOPR,CNT????PR:…

    2022年5月25日
    45
  • spring整合mybatis详细步骤

    spring整合mybatis详细步骤spring整合mybatis的详细步骤

    2022年5月5日
    37
  • 正数、负数和补码_正数原码反码补码

    正数、负数和补码_正数原码反码补码计算机中,正数、负数是怎么区分的呢,如何存放正数和负数?这里,就要用到补码这个概念了,先给出结论吧:正数和负数在计算机其实都是使用补码来存放的,并且在计算机中是没有减法运算的,减法实际上就是补码直接相加。正数和负数的补码补码是计算机存放数据之前对数据做了一种转换操作得到的,与补码相关的几个名词还有原码、反码:1、原码:字节的最高位为符号位,其余表示数值大小,最简单;2、反码:正数的反码和原码一样,负数的反码除最高位符号位外,其他位都取反;3、补码:在反码的基础上加1,这样可以方便计算机进行计算,可

    2022年10月26日
    0
  • AngularJS笔记「建议收藏」

    AngularJS笔记「建议收藏」1.   AngularJS通过ng-directives扩展了HTML。  ng-app指令定义一个AngularJS应用程序。  ng-model指令把元素值(比如输入域的值)绑定到应用程序。  ng-bind指令把应用程序数据绑定到HTML视图。2.  HTML5允许扩展的(自制的)属性,以data-开头。  AngularJS属性以n…

    2022年7月25日
    12

发表回复

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

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