Pagini recente » Cod sursa (job #726903) | Cod sursa (job #2498905) | Cod sursa (job #2906273) | Borderou de evaluare (job #2267939) | Cod sursa (job #586377)
Cod sursa(job #586377)
#include <cstdio>
void getprims(int x, int &_count2, int &_count5){
_count2 = _count5 = 0;
//check 2
while (x && !(x & 1)){
x >>= 1;
++_count2;
}
while (x % 5 == 0){
x /= 5;
++_count5;
}
}
int main(){
freopen("factorial.in", "r", stdin);
freopen("factorial.out", "w", stdout);
int P;
scanf("%d", &P);
int i = 0, count0 = 0, count2 = 0, count5 = 0;
int _count2, _count5;
while (count0 < P){
++i;
getprims(i, _count2, _count5);
count2 += _count2;
count5 += _count5;
count0 = count2 < count5? count2 : count5;
}
if (count0 == P) printf("%d", i);
else printf("-1");
return 0;
}