Hello ! I wanted to solve the factorial (easy) test in nodejs, but i get the “wrong answer” alert every time.
The solutions itself is right, but i probably make mistakes with the input / output.
Because the input in nodejs is an event, its not as straight as in other languages to implement. Can i get some help here ?
Many thanks in advance…
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) { start(chunk) });
function start(chunk){
var chunks = chunk.toString().split('\n');
maxcount = chunks.shift();
chunks = chunks.filter(function(e){return e});
chunks.forEach(function(val,index){
if(maxcount>0){
solveProblem(val);
}
if(maxcount-1>0){process.stdin.destroy();}
maxcount--;
});
}
function solveProblem(numba){
var solution = checkfactorial(numba);
//solution = solution.toString();
console.log(solution);
}
function checkfactorial(number){
var temp = 1;
var sum = 0;
while(temp <= number){
temp = temp*5;
sum = sum + Math.floor(number/temp);
}
return sum;
}