首页 > 试题广场 >

最小公倍数与最大公约数

[编程题]最小公倍数与最大公约数
  • 热度指数:4354 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 256M,其他语言512M
  • 算法知识视频讲解
度度熊请你找出两个数,满足尽量大。输出最大的.
其中表示的最小公倍数,表示的最大公约数。

输入描述:
一行一个数字


输出描述:
一行一个数字表示最大的
示例1

输入

5

输出

19
示例2

输入

3

输出

5
import java.util.Scanner;
import java.math.BigInteger;
// 注意类名必须为 Main, 不要有任何 package xxx 信息
public class Main {
//真的容易超时,还得是大整数相乘啊
    public static void process(String n) {
        if (n.charAt(0) == '1') {
            System.out.println(1);
            return ;
        }
        BigInteger n1 = new BigInteger(n);
        BigInteger n2 = new BigInteger(n);
        BigInteger n3= n2.subtract(new BigInteger("1"));
        BigInteger res=n1.multiply(n3).subtract(new BigInteger("1"));
        System.out.println(res);
    }
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        // 注意 hasNext 和 hasNextLine 的区别
        while (in.hasNext()) { // 注意 while 处理多个 case
            String n = in.next();
            process(n);
        }
    }
}
发表于 2023-03-29 21:45:22 回复(0)
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long a = sc.nextLong();
        System.out.println(a*(a-1)-1);
    }
}
发表于 2023-03-07 13:50:09 回复(0)