算法训练 5-1最小公倍数

问题描述

编写一函数lcm,求两个正整数的最小公倍数。

样例输入

一个满足题目要求的输入范例。
例:

3 5

样例输出

与上面的样例输入对应的输出。
例:

数据规模和约定

输入数据中每一个数的范围。
  例:两个数都小于65536。

int型范围是2的31次方-1=2147483647
65536平方为4294967296所以不能用结果不能用int
long范围2的64次方-1=9223372036854775807可以
用穷举法:

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int a=sc.nextInt();
        int b=sc.nextInt();
        int c=0;
        if(a>b) {
            c=a;
        }
        else {
            c=b;
        }
        long sum=0;
        for(int i=1;i

你可能感兴趣的:(算法训练 5-1最小公倍数)