Mai intai trebuie sa te autentifici.
Cod sursa(job #1024076)
Utilizator | Data | 8 noiembrie 2013 10:20:56 | |
---|---|---|---|
Problema | Factorial | Scor | 50 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.67 kb |
#include <iostream>
#include<fstream>
using namespace std;
int p;
ifstream f("fact.in");
ofstream g("fact.out");
int fun(long long x)
{
long long c=5,nr=0;
while(x/c!=0)
{
nr=nr+x/c;
c=c*5;
}
return nr;
}
int binary(long long st,long long dr)
{
long long med=(st+dr)/2;
long long x=fun(med);
if(med%5==0&&x==p)
return med;
else
if(x<p)
return binary(med+1,dr);
else
return binary(st,med-1);
if(st>dr)
return -1;
}
int main()
{
long long n;
f>>p;
if(p==0)
g<<1<<endl;
else
g<<binary(1,100000000)<<endl;
return 0;
}