[UCSD白板题] Greatest Common Divisor
Problem Introduction
The greatest common divisor \(GCD(a, b)\) of two non-negative integers \(a\) and \(b\) (which are not both equal to 0) is the greatest integer \(d\) that divides both \(a\) and \(b\).
Problem Description
Task.Given two integer \(a\) and \(b\), find their greatest common divisor.
Input Format.The two integers \(a\),\(b\) are given in the same line separated by space.
Constraints. \(1 \leq a, b \leq 2 \cdot 10^9\).
Output Format. Output \(GCD(a,b)\).
Sample 1.
Input:
18 35
Output:
1
Sample 2.
Input:
28851538 1183019
Output:
17657
Solution
# Uses python3
import sys
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
if __name__ == "__main__":
input = sys.stdin.read()
a, b = map(int, input.split())
print(gcd(a, b))
[UCSD白板题] Greatest Common Divisor的更多相关文章
- [UCSD白板题] Longest Common Subsequence of Three Sequences
Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...
- [UCSD白板题] Least Common Multiple
Problem Introduction The least common multiple of two positive integers \(a\) and \(b\) is the least ...
- 2018CCPC桂林站G Greatest Common Divisor
题目描述 There is an array of length n, containing only positive numbers.Now you can add all numbers by ...
- CCPC2018 桂林 G "Greatest Common Divisor"(数学)
UPC备战省赛组队训练赛第十七场 with zyd,mxl G: Greatest Common Divisor 题目描述 There is an array of length n, contain ...
- greatest common divisor
One efficient way to compute the GCD of two numbers is to use Euclid's algorithm, which states the f ...
- 最大公约数和最小公倍数(Greatest Common Divisor and Least Common Multiple)
定义: 最大公约数(英语:greatest common divisor,gcd).是数学词汇,指能够整除多个整数的最大正整数.而多个整数不能都为零.例如8和12的最大公因数为4. 最小公倍数是数论中 ...
- 845. Greatest Common Divisor
描述 Given two numbers, number a and number b. Find the greatest common divisor of the given two numbe ...
- hdu 5207 Greatest Greatest Common Divisor 数学
Greatest Greatest Common Divisor Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://acm.hdu.edu.cn/ ...
- LeetCode 1071. 字符串的最大公因子(Greatest Common Divisor of Strings) 45
1071. 字符串的最大公因子 1071. Greatest Common Divisor of Strings 题目描述 对于字符串 S 和 T,只有在 S = T + ... + T(T 与自身连 ...
随机推荐
- Linux QT
Check system version 1. cat /proc/version mike@sp-ThinkPad-X220:~$ cat /proc/versionLinux version 3 ...
- Form提交是会刷新页面的
今天发现如果页面中有form,点击提交按钮是会刷新页面的,为了禁止页面刷新行为,可以这么做: <form class="form-horizontal" id="u ...
- UML类图画法及其之间的几种关系(转)
UML类图画法及其之间的几种关系 最近做重构项目,需要画一下类图,发现类图的画法及其之间的几种关系已经淡忘了很多,所以整理总结一下,有问题的地方大家可以一起讨论下. 文章目录如下: 类图画法 类之间的 ...
- Ubuntu如何更新源
Ubuntu的源其实就是更新各种软件包需要用到镜像网站, 当大家在虚拟机上安装Linux镜像的时候肯定会遇到各种Linux软件没有安装,当你用apt-get安装的时候它会提示无效的网址,这个时候你就需 ...
- Xilium.CefGlue CEF Chrome 自动上传文件不弹出对话框 CefDialogHandler
关键代码如下,如何使用Handler,还不清楚的请继续搜索 internal sealed class WyzCefDialogHandler : CefDialogHandler { ...
- 反射——反射API,使用反射创建数组
反射API Java.lang.Reflect库 ① Class类与Java.lang.Reflect类库一起对反射的概念进行支持. ② java.lang包下: a) Cla ...
- 使用OPENROWSET、Microsoft.ACE.OLEDB实现大数据量的高效导入
首先说明使用的环境是:java和Sqlserver. 最近公司需要进行大数据量的导入操作.原来使用的是Apache POI,虽然可以实现功能,但是因为逻辑处理中需要进行许多校验,处理速度太慢,使用多线 ...
- june 14
Thank you for your applying for employment with our company. Your application is now being processed ...
- nodejs npm常用命令
npm是一个node包管理和分发工具,已经成为了非官方的发布node模块(包)的标准.有了npm,可以很快的找到特定服务要使用的包,进行下载.安装以及管理已经安装的包. 1.npm install m ...
- ng-repeat && ng-options的故事
ng-repeat && ng-options的故事 1. <select class="input-small" ng-model="newH ...