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.

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.

题意:给一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;
}

Codeforces Round #296 (Div. 2) A. Playing with Paper的更多相关文章

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

    题目传送门 /* 水题 a或b成倍的减 */ #include <cstdio> #include <iostream> #include <algorithm> ...

  2. Codeforces Round #184 (Div. 2) E. Playing with String(博弈)

    题目大意 两个人轮流在一个字符串上删掉一个字符,没有字符可删的人输掉游戏 删字符的规则如下: 1. 每次从一个字符串中选取一个字符,它是一个长度至少为 3 的奇回文串的中心 2. 删掉该字符,同时,他 ...

  3. Codeforces Round #296 (Div. 1) C. Data Center Drama 欧拉回路

    Codeforces Round #296 (Div. 1)C. Data Center Drama Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xx ...

  4. CodeForces Round #296 Div.2

    A. Playing with Paper 如果a是b的整数倍,那么将得到a/b个正方形,否则的话还会另外得到一个(b, a%b)的长方形. 时间复杂度和欧几里得算法一样. #include < ...

  5. Codeforces Round #296 (Div. 1) E. Triangles 3000

    http://codeforces.com/contest/528/problem/E 先来吐槽一下,一直没机会进div 1, 马力不如当年, 这场题目都不是非常难,div 2 四道题都是水题! 题目 ...

  6. Codeforces Round #522 (Div. 2) C. Playing Piano

    C. Playing Piano 题目链接:https://codeforces.com/contest/1079/problem/C 题意: 给出数列{an},现在要求你给出一个数列{bn},满足: ...

  7. 字符串处理 Codeforces Round #296 (Div. 2) B. Error Correct System

    题目传送门 /* 无算法 三种可能:1.交换一对后正好都相同,此时-2 2.上面的情况不可能,交换一对后只有一个相同,此时-1 3.以上都不符合,则不交换,-1 -1 */ #include < ...

  8. Codeforces Round #296 (Div. 2) A B C D

    A:模拟辗转相除法时记录答案 B:3种情况:能降低2,能降低1.不能降低分别考虑清楚 C:利用一个set和一个multiset,把行列分开考虑.利用set自带的排序和查询.每次把对应的块拿出来分成两块 ...

  9. Codeforces Round #296 (Div. 1) B - Clique Problem

    B - Clique Problem 题目大意:给你坐标轴上n个点,每个点的权值为wi,两个点之间有边当且仅当 |xi - xj| >= wi + wj, 问你两两之间都有边的最大点集的大小. ...

随机推荐

  1. 时间运算函数 CATT_ADD_TO_TIME

  2. VC Office2007界面对话框实现

    我们知道VS2008SP1之后,MFC就多了一个功能包,可以快速的建立一个ribbon的界面,视觉样式可以在office 2007蓝.黑等颜色之间切换,这对于单文档/多文档做界面非常方便,而且也蛮好看 ...

  3. ASC(22)H(大数+推公式)

    High Speed Trains Time Limit: 4000/2000MS (Java/Others)Memory Limit: 128000/64000KB (Java/Others) Su ...

  4. html5的自定义data-*属性和jquery的data()方法的使用

    人们总喜欢往HTML标签上添加自定义属性来存储和操作数据.但这样做的问题是,你不知道将来会不会有其它脚本把你的自定义属性给重置掉,此外,你这样做也会导致html语法上不符合Html规范,以及一些其它副 ...

  5. tomcat7 启动报错(转)

    不加载任何自己的项目启动即报错:   严重: Error deploying web application directory D:\tomcat7.0.30\webapps\docs java.l ...

  6. 了解sota字符界面(章节4.1)

    4 SOTA操作 4.1 SOTA字符界面 sotaCC是字符界面管理sota系统程序 . 在/.../sota/bin/目录下,启动sotaCC.在终端的该目录下输入指令“./sotaCC”,启动s ...

  7. JVM学习笔记(一)------的基本结构

    从Java视台的逻辑结构.我们能够从图中学习JVM: 您可以从图表清楚地看到Java该平台包括各种逻辑模块.还可以学习JDK与JRE差异 于JVM它们的物理结构,我们可以看一下从图计划: 为JVM学习 ...

  8. alv行可编辑时带出描述

    ALV显示可以编辑的状态下可以带出描述信息等,比如维护表程序输入公司代码时需要带出公司代码的描述,这时就需要通过下面事件来触发 定义一个类: CLASS lcl_event_receiver DEFI ...

  9. [置顶] 关于redhat系统yum源的配置2

    (二)配置yum源(官方) 1.在终端输入以下命令(RHEL6/CentOS6) wget http://lug.ustc.edu.cn/wiki/_export/code/mirrors/help/ ...

  10. Spring MVC 数据验证——validate注解方式

    1.说明 学习注解方式之前,应该先学习一下编码方式的spring注入.这样便于理解验证框架的工作原理.在出错的时候,也能更好的解决这个问题.所以本次博客教程也是基于编码方式.仅仅是在原来的基础加上注解 ...