Cod sursa(job #3141289)
| Utilizator | Data | 13 iulie 2023 14:29:40 | |
|---|---|---|---|
| Problema | Factorial | Scor | 0 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.54 kb |
#include <fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long zero(int x)
{
long sum=0, c=5;
while(x)
{
sum+=x/c;
x/=c;
}
return sum;
}
long cb(long st, long dr, long val)
{ long mij;
while(st<dr)
{
mij=(st+dr)/2;
if(zero(val)<p) st=mij+1;
else dr=mij;
}
if(zero(st)==val)return st;
else return -1;
return 0;
}
int main()
{
long n, p;
fin>>p;
fout<<cb(1, 1e17, p);
return 0;
}