90分的注意那个最后最小公倍数的大小 不能用int
查看原帖
90分的注意那个最后最小公倍数的大小 不能用int
1590234
dandanya楼主2025/7/24 01:06
import java.util.Scanner;

public class Main
{
    public static long get(long a,long b)
    {
        long numa=a;
        long numb=b;
        while(numb>0)
        {
            long r=numa%numb;
            numa=numb;
            numb=r;
        }
        return a*b/numa;
    }


    public static void main(String[] args)
    {
        int len;
        Scanner sc=new Scanner(System.in);
        len=sc.nextInt();
        int num[]=new int[len];
        for(int i=0;i<len;i++)
        {
            num[i]=sc.nextInt();
        }
        long temp=num[0];
        for(int i=1;i<len;i++)
        {
            temp=get(temp,num[i]);
        }
        System.out.println(temp);
    }
}

2025/7/24 01:06
加载中...