Skip to content

Commit

Permalink
feat: implement function
Browse files Browse the repository at this point in the history
  • Loading branch information
SergeyGuchok committed Mar 11, 2019
1 parent 8d7fbc8 commit b9c3e8f
Showing 1 changed file with 17 additions and 20 deletions.
37 changes: 17 additions & 20 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
module.exports = function getZerosCount(number, base) {
const simple = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251];
let mnoj = 0;
let time = base;
let maxSimple = 0;

for (let i = 0; simple[i] <= base; i += 1) {
if (base % simple[i] == 0) {
maxSimple = simple[i]
let result = Number.MAX_VALUE;
let j = base;
for (let i = 2; i <= base; i += 1) {
if (j % i === 0) {
let p = 0;
while (j % i === 0) {
j = j / i;
p++;
}
let c = 0;
let z = Math.floor(number / i);
while (z > 0) {
c += z;
z = Math.floor(z / i);
}
result = Math.min(result, Math.floor(c / p))
}
}

while (time % maxSimple === 0) {
mnoj++;
time = time / maxSimple;
}

let count = 0;
while (number > 0) {
number = Math.floor(number / maxSimple);
count += number;
}
return Math.floor(count / mnoj);
return result;
}

0 comments on commit b9c3e8f

Please sign in to comment.