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的更多相关文章

  1. [UCSD白板题] Longest Common Subsequence of Three Sequences

    Problem Introduction In this problem, your goal is to compute the length of a longest common subsequ ...

  2. [UCSD白板题] Greatest Common Divisor

    Problem Introduction The greatest common divisor \(GCD(a, b)\) of two non-negative integers \(a\) an ...

  3. [UCSD白板题] Maximize the Value of an Arithmetic Expression

    Problem Introduction In the problem, your goal is to add parentheses to a given arithmetic expressio ...

  4. [UCSD白板题] Compute the Edit Distance Between Two Strings

    Problem Introduction The edit distinct between two strings is the minimum number of insertions, dele ...

  5. [UCSD白板题] Take as Much Gold as Possible

    Problem Introduction This problem is about implementing an algorithm for the knapsack without repeti ...

  6. [UCSD白板题] Primitive Calculator

    Problem Introduction You are given a primitive calculator that can perform the following three opera ...

  7. [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 ...

  8. [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 ...

  9. [UCSD白板题] Sorting: 3-Way Partition

    Problem Introduction The goal in this problem is to redesign a given implementation of the randomize ...

随机推荐

  1. 用JS做的时钟

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. IntelliJ设置鼠标悬浮提示和修改快捷键

    IntelliJ设置鼠标悬浮提示和修改快捷键 设置鼠标悬浮提示 修改快捷键 进入设置菜单 删除原来的快捷键(注:你可以选择保留原来的快捷键,同时使用两个快捷键) Good Luck

  3. javaScript 查询字符串参数 获取

    function getQueryStringArgs() { //取得查询字符串并去掉开头的问号 var qs = (location.search.length > 0 ? location ...

  4. Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute'

    [TypeLoadException: Could not load type 'System.Runtime.CompilerServices.ExtensionAttribute' from as ...

  5. [Zigbee]定时器1

    注意:在定时器可以使用一个输入/输出引脚之前,所需的 I/O 引脚必须配置为定时器 1 的外设引脚. 定时器1的引脚映射方案选用是备用2方案:P07对应通道3.P06-通道4.P12-通道0.P11- ...

  6. quartz_job

    quartz--job job是执行任务所需的Java类. 在quartz中job分为两种,有状态和无状态的.job是无状态的,statefuljob是有状态的. 通过实现job或者statefulj ...

  7. 使用 Eclipse 插件部署 Java 应用

    打开 Eclipse,点击顶部的菜单『Help/Install New Software/Add』. 选择对话框顶部『Work with』 后面的『Add』按钮,并点击『Archive』选择下载到本地 ...

  8. 第一次将内容添加到azure event hubs

    由于每秒数据吞吐量巨大,需要将实时数据存到event hubs,再由event hubs定时定量保存到document DB. event hubs的介绍详见微软官页:https://azure.mi ...

  9. HTML5 --照抄书里的代码但函数无法执行、求分析( Uncaught ReferenceError: xxx is not defined)

    在js文件里写一个方法传参数: moveElement(id,name,price) { alert("id:"+id+"name:"+name+"p ...

  10. 一般html5 手机端头部需要

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...