Posted By

binaryadder on 10/15/11


Tagged


Versions (?)

Problem 5


 / Published in: Java
 

Project Euler Question 5

"2520 is the smallest number that can be divided by each of the numbers from 1 to 10 without any remainder.

What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?"

Output:

232792560

  1. public class Prob5{
  2. public static void main(String[] argsv){
  3. int num = 2521;
  4. while(!div(num, 1, 20)){
  5. num++;
  6. }
  7. System.out.println(num);
  8. }
  9.  
  10. private static boolean div(int n, int min, int max){
  11. for(int i = min; i <= max; i++){
  12. if(n % i != 0)
  13. return false;
  14. }
  15. return true;
  16. }
  17. }

Report this snippet  

You need to login to post a comment.