Skip to content

Instantly share code, notes, and snippets.

@nagat01
Created February 6, 2015 22:18
Show Gist options
  • Select an option

  • Save nagat01/01bd8ff25cc469775b45 to your computer and use it in GitHub Desktop.

Select an option

Save nagat01/01bd8ff25cc469775b45 to your computer and use it in GitHub Desktop.
<div>problem5 (10) = <p id="a10"></p></div>
<div>problem5 (20) = <p id="a20"></p></div>
<script>
function problem5 (x) {
var primes = [];
for(i = 2; i < x; i++) {
var isPrime = true;
for(j = 0; j < primes.length; j++) {
if(i % primes[j] == 0)
isPrime = false;
}
if(isPrime) {
primes.push(i); }
}
var result = 1;
for(i = 0; i < primes.length; i++) {
var p = primes[i];
result *= Math.pow(p, Math.floor(Math.log(x) /Math.log(p)));
}
return result;
}
document.getElementById("a10").innerHTML = problem5(10);
document.getElementById("a20").innerHTML = problem5(20);
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment