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. linux命令行下的ftp 多文件下载和目录下载

    安装:yum install ftp 使用:ftp + ip (未进入ftp状态下运行) ----------------------------------------- 目标ftp服务器是一个非标 ...

  2. [Docker] docker 基础学习笔记4(共6篇)

    离线安装nginx   apache 如何启动war包   linux 离线升级内核   nginx和Apache的使用   nginx 的负载均衡配置 是如此的简单,比weblogic的要简单100 ...

  3. Python在Windows下安装第三方库浅谈

    在用python编写代码时,往往需要用到第三方库,那么python如何去用第三方库呢,首先我们先来看看是如何安装的,方法可能会很多,但这边只介绍一种,其它请百度或google 比如asyncio,这里 ...

  4. DOCTYPE的重要性

    <!DOCTYPE>是文档类型声明: 声明必须是 HTML 文档的第一行,位于 <html> 标签之前.明不是 HTML 标签:它是指示 web 浏览器关于页面使用哪个 HTM ...

  5. socket阻塞与非阻塞,同步与异步

    socket阻塞与非阻塞,同步与异步 作者:huangguisu 转自:http://blog.csdn.net/hguisu/article/details/7453390 1. 概念理解 在进行网 ...

  6. Jquery当中当data为json串时,eval('(' +data+ ')')的解释

    var dataObj = eval('(' +data+ ')') data是返回来的json. dataObj就是json对象了. 为什么要添加 '(' 与 ')' 作为开始于结尾呢? json是 ...

  7. 字节b换算kb/mb/gb/tb/pb

    public static string HumanReadableFilesize(double size) { string[] units = new string[] { "B&qu ...

  8. Button四角有弧度及按下显示不同的颜色

    一般的button都是矩形或者正方形,但为了显示不同的效果,让界面更美化,可以对其进行处理!!! 1.四角有弧度的button 2.按下button显示不同的颜色 实现步骤: 首先在drawable文 ...

  9. Textrank算法介绍

    先说一下自动文摘的方法.自动文摘(Automatic Summarization)的方法主要有两种:Extraction和Abstraction.其中Extraction是抽取式自动文摘方法,通过提取 ...

  10. treap树模板

    ///treap树模板 typedef struct Node ///节点的结构体 { Node *l,*r; int val,pri; ///节点的值和优先级 int sz; ///节点子树的节点数 ...