Pagini recente » Cod sursa (job #2045094) | Cod sursa (job #536894) | Cod sursa (job #932758) | Cod sursa (job #1787137) | Cod sursa (job #3174900)
#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) {
if (n<5) {
return 0;
}
unsigned long long s=0,p=5;
while (p<=n){
s+=n/p;
p*=5;
}
return s;
}
int main()
{
unsigned int p;
fin >> p;
unsigned int r=24999999,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+1;
} else if ( Zero_La_Final_Fact(probe)>p) {
r=probe-1;
}
probe=(l+r)/2;
}
fout << "-1";
return 0;
}