[UCSD白板题] Least Common Multiple
Problem Introduction
The least common multiple of two positive integers \(a\) and \(b\) is the least positive integer \(m\) that is divisible by both \(a\) and \(b\).
Problem Description
Task.Given two integers \(a\) and \(b\), find their least common multiple.
Input Format.The two integers \(a\) and \(b\) are given in the same line separated by space.
Constraints. \(1 \leq a, b \leq 2 \cdot 10^9\).
Output Format. Output the least common multiple of \(a\) and \(b\).
Sample 1.
Input:
6 8
Output:
24
Sample 2.
Input:
28851538 1183019
Output:
1933053046
Solution
# Uses python3
import sys
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def lcm(a, b):
return a*b//gcd(a,b)
if __name__ == '__main__':
input = sys.stdin.read()
a, b = map(int, input.split())
print(lcm(a, b))
[UCSD白板题] Least Common Multiple的更多相关文章
- [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白板题] Greatest Common Divisor
Problem Introduction The greatest common divisor \(GCD(a, b)\) of two non-negative integers \(a\) an ...
- [UCSD白板题] Maximize the Value of an Arithmetic Expression
Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...
- [UCSD白板题] Compute the Edit Distance Between Two Strings
Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...
- [UCSD白板题] Take as Much Gold as Possible
Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...
- [UCSD白板题] Primitive Calculator
Problem Introduction You are given a primitive calculator that can perform the following three opera ...
- [UCSD白板题] Points and Segments
Problem Introduction The goal in this problem is given a set of segments on a line and a set of poin ...
- [UCSD白板题] Number of Inversions
Problem Introduction An inversion of a sequence \(a_0,a_1,\cdots,a_{n-1}\) is a pair of indices \(0 ...
- [UCSD白板题] Sorting: 3-Way Partition
Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...
随机推荐
- 转载:Solr的自动完成实现方式(第二部分:Suggester方式)
转自:http://www.cnblogs.com/ibook360/archive/2011/11/30/2269077.html 在Solr的自动完成/自动补充实现介绍(第一部分) 中我介绍了怎么 ...
- scala学习之: Flatten a nested list structure
题目要求: (**) Flatten a nested list structure. Example: scala> flatten(List(List(1, 1), 2, List(3, L ...
- 抢凳子日数据sql
--先找到档期select * from hv_item_info a where a.report_begdate > '2016-07-28' and a.report_begdate &l ...
- I/O流——其他流
其他流 一.ObjectInputStream/ObjectOutputStream ① ObjectInputStream和ObjectOutputStream分别与FileInputStream和 ...
- Chrome & Linux font
1 $ sudo apt-get install texlive-full # 较大 2 $ mkdir -p ~/.fonts 3 下载这个win7字体包解压后放到~/.fonts下 4 $ sud ...
- python 传参open
# Author:mologa k = "ab" for i in k: with open('%s.txt'%i,'w') as f: f.write("hello&q ...
- MAC 安装j2ee.sh的办法
It says it needs the DISPLAY variable set - what do I need to set it to? Instead of saying: ./java_e ...
- command line
command line terminal vim 编辑工具 vim 编辑命令 j 光标上移 k 光标下移 l 光标左移 h 光标右移 x / dd 删除一行 v 多行模式 :w 保存 :q 不保存退 ...
- Twitter的分布式自增ID算法snowflake (Java版)
概述 分布式系统中,有一些需要使用全局唯一ID的场景,这种时候为了防止ID冲突可以使用36位的UUID,但是UUID有一些缺点,首先他相对比较长,另外UUID一般是无序的. 有些时候我们希望能使用一种 ...
- [Gnu]Centos7 解决 gdb 提示 Missing separate debuginfos
Centos7 上使用gdb: $ gdb php $ run /home/www/2.php 运行完 run,后面跟着很长的提示: …. Missing separate debuginfos, u ...