Pagini recente » Cod sursa (job #2844715) | Cod sursa (job #1655629) | Profil Saitama | Cod sursa (job #3253434) | Cod sursa (job #3174938)
#include <iostream>
#include <cmath>
#include <fstream>
std::ifstream fin("fact.in");
std::ofstream fout("fact.out");
unsigned long long Zero_La_Final_Fact(unsigned int n) {
n-=n%5;
unsigned long long s=0,p=5;
while (p<=n){
s+=n/p;
p*=5;
}
return s;
}
int main()
{
unsigned int p;
fin >> p;
if (p==0) {
fout << '1';
return 0;
}
unsigned int r=24999995,l=1,probe=(l+r)/2;
while (l<r) {
if (Zero_La_Final_Fact(probe)==p) {
fout << probe-probe%5;
return 0;
} else if( Zero_La_Final_Fact(probe)<p) {
l=probe+5;
} else if ( Zero_La_Final_Fact(probe)>p) {
r=probe-5;
}
probe=(l+r)/2;
}
fout << "-1";
return 0;
}