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)
上一篇 2022年1月22日 上午8:00
下一篇 2022年1月22日 上午9:00


相关推荐

  • 基于TCP的socket编程原理概述「建议收藏」

    基于TCP的socket编程原理概述「建议收藏」解:服务器端:1)创建套接字socket;2)bind(将套接字绑定到本地地址和端口上)3)listen(将套接字设置为监听模式,准备接受连接请求)4)accept等待客户请求到来,当请求到后,接受连接请求,返回一个新的对应于此次连接的套接字5)用返回的套接字和客户端进行通信(send/receive)6)返回等待另个客户请求7)关闭套接字客户端:1)创

    2022年10月18日
    5
  • VMware下载安装教程(vbox虚拟机安装教程)

    全网最详细的VMware虚拟机下载安装教程第一步下载虚拟机1.进入VMware官网,点击左侧导航栏中的下载,选择下拉列表中的产品下载,再点击图中标记的WorkstationPro,如下图所示。2.选择自己需要的版本和操作系统,在这里以Windows系统为例,点击转至下载,如下图所示。-3.点击转至下载后也在此处可以选择版本。选择好版本后点击立即下载。如下图所示。4.注意,需要登录之后才能下载。若无账号可点击注册后登录。如下图所示。二、安装虚拟机1.进入下载路径,双击.

    2022年4月10日
    93
  • Grok发布了Grok Studio 和 Workspaces两个强大的功能。该如何使用?如何使用Grok3 API?

    Grok发布了Grok Studio 和 Workspaces两个强大的功能。该如何使用?如何使用Grok3 API?

    2026年3月15日
    3
  • AspNetCore 中使用 Newlife.IdentityServer4 管理 IdentityServer 数据

    AspNetCore 中使用 Newlife.IdentityServer4 管理 IdentityServer 数据本文讲述如何实现 IdentityServ 数据的管理 包括添加删除等基础操作和相应 UI 后端此处直列关键点 不做详细描述 此项目跟普通的数据库管理无异 所以只做简单记录实例请查看这里添加引用新建 asp netcore 项目 IdentityServ XCode 引用 代码入口添加服务 视自己情况而定 options 的参数需要与前端配合添加 Easy Admin 引用 Easy Admin 包含了具有增删查改的基类控制器 并且封装了统一的响应结果 真实结果包含在 Data 属性

    2026年3月19日
    3
  • 《JavaScript 模式》读书笔记(5)— 对象创建模式1「建议收藏」

    这又是一个新的开始,对象的重要性不言而喻。在JavaScript中创建对象是十分容易的,之前聊过的对象字面量和构造函数都可以达到目的。但是本篇中,我们越过那些方法,以寻求一些额外的对象创建模式。本篇

    2022年3月25日
    46
  • apache安装ssl证书_apache ssl证书配置

    apache安装ssl证书_apache ssl证书配置1、apache错误提示libz.a:couldnotreadsymbols:Badvalue”重新安装openssl加上-fPIC和enable-shared参数./config-fPIC–prefix=/usr/local/openssl1.0.1 enable-shared2、apache的httpd.conf缺乏LoadModulessl_module

    2025年11月30日
    6

发表回复

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

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