[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 ...
随机推荐
- IOS (APP 启动 相应处理)
APP 每次启动的入口都是通过: - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSD ...
- SHOPNC占用CPU过高
今天一个SHOPNC商城突然变慢,查看服务器情况,发现MYSQL占用181%CPU,然后查看PHP慢查询,发现这样的内容 [22-Nov-2016 20:55:41] [pool www] pid 5 ...
- Selenium调用Chrome,Firefox,IE
C#环境下,使用Selenium调用不同的浏览器,可以使用如下方法: IWebDriver driver = null; string Browser =null; if (Browser.Equal ...
- MySQL查询今天/本周/上周/本月/上个月份的数据
MySQL查询的方式很多,下面为您介绍的MySQL查询实现的是查询本周.上周.本月.上个月份的数据,如果您对MySQL查询方面感兴趣的话,不妨一看. 查询当前今天的数据 SELECT name,sub ...
- C语言学习笔记(二)_system系统调用及posix说明
1.9 System系统调用 System库函数的功能是执行操作系统的命令或者运行指定的程序.system库函数的调用需要#include<stdlib.h>这个头文件. #include ...
- js Function.call
提到上述的概念之前,首先想说说javascript中函数的隐含参数:arguments Arguments 该对象代表正在执行的函数和调用它的函数的参数. [function.]arguments ...
- KMP匹配算法
先来说一下回溯法匹配字符串: 对于主字符串有一个target_index,以target_index(不动)为起点,匹配字符串pattern的长度+target_index为终点,逐个进行比较,当发现 ...
- ASP.NET5 Beta8可用性
ASP.NET5 beta8现已上都的NuGet作为一个工具升级到Visual Studio2015!此版本极大地扩展.NET核心对OS X和Linux所支持的范围.您现在可以使用网络,加密和全球化特 ...
- SAP 创建物料主数据分类视图特性
1.CL01创建物料分类 2.去CT04中去创建特性值 创建完成之后保存, 3.创建物料的分类视图,选择相应的特性值
- Mysql插入数据为何要加上" ` "(Esc下面那个按键符号)?
资料上和以前学习的SQL语言,往数据库里面插入数据语句是这样的 INSERT INTO test_table (clo_1, col_2) VALUES("this is value of ...