Project Euler #5: Smallest multiple

  • + 0 comments

    public static void main(String[] args) { Scanner in = new Scanner(System.in); int t = in.nextInt(); for(int a0 = 0; a0 < t; a0++){ int n = in.nextInt(); System.out.println(lcm(n));

    }
    }
    public static int lcm(int n){
        int result=1;
        for(int i=2;i<=n;i++){
            result=result*i/gcd(result,i);
        }
        return result;
    
    }
    public static int gcd(int n,int o){
        if(o==0)
            return n;
    
       return gcd(o,n%o);
    }