Cod sursa(job #1240972)
| Utilizator | Data | 12 octombrie 2014 13:56:18 | |
|---|---|---|---|
| Problema | Factorial | Scor | 85 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.61 kb |
#include <fstream>
#include <math.h>
using namespace std;
ifstream fin ( "fact.in" ) ;
ofstream fout ( "fact.out" ) ;
long long s,x,p;
long long check(long long x)
{
long long s=0;
for(long long i=5;i<=x;i=i*5)
s=s+x/i;
return s;
}
int main()
{
fin>>p;
long long st=1,sol;
long long dr=500000000;
while(st<=dr)
{
long long mij=(st+dr)/2;
long long k =check(mij);
if(k>p)
dr=mij-1;
else if ( k < p ) st=mij+1;
else if ( k == p ){
sol = mij ;break;
}
}
while(sol%5!=0)
sol--;
fout<<sol;
return 0;
}
