Skip to content

Instantly share code, notes, and snippets.

@goyuninfo
Created May 20, 2014 22:29
Show Gist options
  • Save goyuninfo/9aadfc42768aef1014e7 to your computer and use it in GitHub Desktop.
Save goyuninfo/9aadfc42768aef1014e7 to your computer and use it in GitHub Desktop.
Project Euler Smallest multiple
package euler;
/**
* @author i88.ca
*
*/
public class P5 {
// refers to overview in project Euler.
public static void main(String[] args) {
int[] primes = { 2, 3, 5, 7, 11, 13, 17, 19 };
int[] a = new int[primes.length];
int result = 1;
int limit = (int) Math.sqrt(20);
for (int i = 0; i < a.length; i++) {
if (i <= limit) {
a[i] = (int) Math.floor(Math.log(20) / Math.log(primes[i]));
} else {
a[i] = 1;
}
System.out.println(a[i]);
result *= Math.pow(primes[i], a[i]);
}
System.out.println(result);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment