[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 ...
随机推荐
- Android菜鸟成长记16 -- JSON的解析
JSON的定义 一种轻量级的数据交换格式,具有良好的可读和便于快速编写的特性.业内主流技术为其提供了完整的解决方案(有点类似于正则表达式 ,获得了当今大部分语言的支持),从而可以在不同平台间进行数据 ...
- 新版react踩坑总结
使用es6语法与原本es5语法几个有区别的地方 1.React.creatClass与React.Component var Component = React.createClass({ rende ...
- JSP(include指令与<jsp:include>动作的区别)
<%@ page language= "java" contentType="text/html;charset=UTF-8" %><html ...
- Struts框架——(二)Struts原理with登录实例
二. Struts基本工作流程 假设现在有以下情景: 用户正在浏览一个用STRUTS的技术构建的网站主页,主页上有个登陆表单,用户填好登陆名和密码,单击"登陆"按钮,就激活了以下一 ...
- Window 命令
tracert XXX.XXX.XXX.XXX 路由追踪命令,可以显示到目的IP所经过的路由
- 复制本地文件到HDFS本地测试异常
项目中需要将本地文件拷贝到hdfs上,由于本人比较懒,于是使用擅长的Java程序通过Hadoop.FileSystem.CopyFromLocalFile方法来实现. 在本地(Window 7 环境) ...
- iphone中button按钮显示为圆形解决
iphone中button按钮显示为圆形解决: 添加样式: -webkit-appearance:button; 如果需要为直角: border-radius:0 在源码中添加如:style=&quo ...
- DNS弹窗广告遭遇
事情是这样的,不久前,我跟往常一样打开某新闻网页的时候,发现右下角有弹窗广告,并且在原页面任意位置点击,都会打开一个广告页面,然后原页面才能正常点击,手法太低劣了,不像是网站挂的广告,然后打开其它网页 ...
- Logstash 安装与配置
一.Logstash 描述 简单而又强大的数据抽取与处理工具,相比于flums一整本书的描述强大而又好用. 还记得我13年用python写了一个数据抽取.校验工具,设计思路也同样是拆解处理过程模板,然 ...
- 迅雷VIP帐号获取小工具
自己写的迅雷vip帐号获取工具,主要是熟悉一下正则表达式 下载地址: 迅雷VIP获取工具 另附vip防踢补丁,不能使用最新迅雷,我使用的是迅雷尊享版2.0.12.258,使用了一段时间,至少没被踢出来 ...