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. Objective-C基础笔记(5)Protocol

    Protocol简单来说就是一系列方法的列表,当中声明的方法能够被不论什么类实现.这中模式一般称为代理(delegation)模式. 在IOS和OS X开发中,Apple採用了大量的代理模式来实现MV ...

  2. C#中的正则 Regex类

    转义符的总结: 开始数 …………………………………………………………. 3 )Regex.matches() 提取所有符合要求的字符串 string str=@"绩大于80,则奖励50元.语 ...

  3. ADO.NET 2SqlDataAdapter、DataSet 的基本用法

    数据集完全独立于数据源,可以与数据源链接或者完全断开,其基本作用是为存储在内存缓存中的的数据提供关系视图 如果只是想读取和显示数据,则值需要使用数据读取器,尤其是处理大量数据的时候 如果需要处理数据, ...

  4. Docker学习笔记(1) — docker 常用命令

    1. docker version显示 Docker 版本信息.2. docker info显示 Docker 系统信息,包括镜像和容器数.3. docker searchdocker search ...

  5. ubuntu 14.04 使用极点五笔输入法

    相比12.04在外观改变不是非常大,但当中细节有些许变化,特别输入法非常不大好用,为此,我们使用fcitx输入法,使用我喜欢的五笔拼音,安装步骤例如以下: 方法一: 最新的方法非常easy: 安装14 ...

  6. Caffe —— Deep learning in Practice

    因工作交接须要. 要将caffe用法及总体结构描写叙述清楚. 鉴于也有同学问过我相关内容, 决定在本文中写个简单的tutorial, 方便大家參考. 本文简单的讲几个事情: Caffe能做什么? 为什 ...

  7. MSSQL - 根据时间倒序删除第一行数据

    delete top(1) from Tb_PaintOut where PaintNumber = (select top (1) PaintNumber from Tb_PaintOut orde ...

  8. os内存使用管理之unix-AIX篇

    os内存使用管理之unix-AIX篇 未完待补充.....

  9. Keepalived安装工具

    装keepalived前,要先检查主机上是否已经安装, ps -ef | grep keepalive 不检查的话.easy把前人装的东西覆盖掉,那么曾经弄的配置文件都没了比較麻烦. 下面都为root ...

  10. jQuery事件大全

    jQuery事件大全 attribute:  $(" p" ).addclass(css中定义的样式类型) 给某个元素添加样式 $(" img" ).attr( ...