当前位置:网站首页>Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
Codeforces Round #296 (Div. 2) A. Playing with Paper[通俗易懂]
2022-07-07 20:03:00 【全栈程序员站长】
大家好,又见面了,我是全栈君。
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;
}
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/116387.html原文链接:https://javaforall.cn
边栏推荐
- 让这个CRMEB单商户微信商城系统火起来,太好用了!
- 目标:不排斥 yaml 语法。争取快速上手
- 使用 BR 备份 TiDB 集群数据到 Azure Blob Storage
- 软件缺陷静态分析 CodeSonar 5.2 新版发布
- 恶魔奶爸 指南帖——简易版
- Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
- 寫一下跳錶
- Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
- [paper reading] maps: Multi-Agent Reinforcement Learning Based Portfolio Management System
- 如何挑选基金产品?2022年7月份适合买什么基金?
猜你喜欢
Small guide for rapid formation of manipulator (12): inverse kinematics analysis
Helix QAC 2020.2 new static test tool maximizes the coverage of standard compliance
Jenkins 用户权限管理
How to meet the dual needs of security and confidentiality of medical devices?
SQL注入报错注入函数图文详解
Apifox interface integrated management new artifact
机械臂速成小指南(十二):逆运动学分析
Nebula importer data import practice
Implement secondary index with Gaussian redis
让这个CRMEB单商户微信商城系统火起来,太好用了!
随机推荐
How to choose financial products? Novice doesn't know anything
Lingyun going to sea | saihe & Huawei cloud: jointly help the sustainable development of cross-border e-commerce industry
Apifox 接口一体化管理新神器
95年专注安全这一件事 沃尔沃未来聚焦智能驾驶与电气化领域安全
Ubuntu安装mysql8遇到的问题以及详细安装过程
I wrote a markdown command line gadget, hoping to improve the efficiency of sending documents by garden friends!
Flask1.1.4 werkzeug1.0.1 source code analysis: Routing
[concept of network principle]
Airiot helps the urban pipe gallery project, and smart IOT guards the lifeline of the city
Prometheus remote_write InfluxDB,unable to parse authentication credentials,authorization failed
Nebula importer data import practice
FTP steps for downloading files from Huawei CE switches
使用高斯Redis实现二级索引
机械臂速成小指南(十一):坐标系的标准命名
有用的win11小技巧
【论文阅读】MAPS: Multi-agent Reinforcement Learning-based Portfolio Management System
Codesonar Webinar
How to meet the dual needs of security and confidentiality of medical devices?
恶魔奶爸 A1 语音听力初挑战
Introduction to referer and referer policy