We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • HackerRank Home

    HackerRank

  • |
  • Prepare
  • Certify
  • Compete
  • Apply
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #5: Smallest multiple
  4. Discussions

Project Euler #5: Smallest multiple

Contest ends in
Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • atulyadav22000
    4 months ago+ 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);
    }
    
    0|
    Permalink
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy