[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 ...
随机推荐
- (转)maven配置之pom.xml配置
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/20 ...
- C# DateTime转Json汇总
DateTime转换成json的时候容易出现不想要的格式,在网上搜索了相关的解决方法copy如下: 参考http://www.newtonsoft.com/json/help/html/DatesIn ...
- AWT布局管理器
布局管理器 容器内可以存放各种组件,而组件的位置和大小是由容器内的布局管理器来决定的.在AWT中为我们提供了以下5种布局管理器: ① FlowLayout 流式布局管理器 ② BorderLa ...
- ruby Matrix 输出 格式化
require 'matrix' class Matrix def to_pretty_s s = "" i = 0 while i < self.column_size s ...
- java环境配置步骤
1. jdk下载 官网:http://www.oracle.com/technetwork/java/javase/downloads/jdk8-downloads-2133151.html ...
- Window下Qt Creator启动错误解决方法
很多电脑现在都是用的是双显卡,高性能的独显和性能比较差但耗电少的集显,在Window10系统下右键点击软件,在"图形处理器"里面可以选择使用什么显卡操作此软件.下面是我在运行Qt ...
- Java泛型 E、T、K、V、N
中的标记符含义: E - Element (在集合中使用,因为集合中存放的是元素) T - Type(Java 类) K - Key(键) V - Value(值) N - Number(数值类型) ...
- 编译Hadoop
Apache Hadoop 生态圈软件下载地址:http://archive.apache.org/dist/hadoop/hadoop下载地址 http://archive.apache.org/d ...
- 实用脚本----Linux下Jdk和Tomcat自动安装shell脚本总结
系统环境为:ubuntu 14.04 一.JDK 自动安装脚本 jdk自动安装bash shell脚本,截止今天(2014/10/15)亲测可用: sudo su #切换到root权限 mkdir / ...
- 激活windows10 LTSB 2016
激活windows10 LTSB 2016 slmgr /ipk DCPHK-NFMTC-H88MJ-PFHPY-QJ4BJ slmgr /skms kms.firadio.net slmgr /at ...