Created
December 23, 2012 06:20
-
-
Save hiroqn/4362280 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var THT = 200000, | |
exp_value = 12, | |
Hash5 = [], | |
Hash2 = []; | |
function getNumOfFactor5(num) { | |
var count = 0, | |
fact = 5; | |
if (Hash5[num]) { | |
return Hash5[num]; | |
} | |
while (fact <= num) { | |
count += ~~(num / fact); | |
fact *= 5; | |
} | |
return Hash5[num] = count; | |
} | |
function getNumOfFactor2(numl) { | |
var count = 0, | |
fact = 2; | |
if (Hash2[l]) { | |
return Hash2[l]; | |
} | |
while (fact <= l) { | |
count += ~~(l / fact); | |
fact *= 2; | |
} | |
return Hash2[l] = count; | |
} | |
var NUM_5FACT_THT = getNumOfFactor5(THT), | |
NUM_2FACT_THT = getNumOfFactor2(THT), | |
d = Date.now(); | |
console.log('answer is : ' + function () { | |
var sum5Fact , sum2Fact, a, b, c, count = 0; | |
for (a = 0; a < THT / 3; a++) { | |
for (b = a; b <= (THT - a) / 2; b++) { | |
c = THT - a - b; | |
sum5Fact = getNumOfFactor5(a) + getNumOfFactor5(b) + getNumOfFactor5(c); | |
if (NUM_5FACT_THT - sum5Fact >= exp_value) { | |
sum2Fact = getNumOfFactor2(a) + getNumOfFactor2(b) + getNumOfFactor2(c); | |
if (NUM_2FACT_THT - sum2Fact >= exp_value) { | |
if (a !== b && b !== c) { | |
count += 6; | |
} else { | |
count += 3; | |
} | |
} | |
} | |
} | |
} | |
return count; | |
}()); | |
console.log('time is : ', (Date.now() - d) / 1000); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment