Cod sursa(job #474446)
| Utilizator | Data | 3 august 2010 19:59:16 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.59 kb |
#include <fstream>
using namespace std;
unsigned long long x,a,b,c,p;
unsigned long long factorial(long long n)
{
unsigned long long zero;
zero=0;
while(n)
{
zero+=n/5;
n/=5;
}
return zero;
}
int main()
{
ifstream fi("fact.in");
ofstream fo("fact.out");
fi>>p;
a=1;
b=18446744073709551614LL;
while(a<b)
{
c=(a+b)/2;
x=factorial(c);
if(x<p) a=c+1;
if(x>p) b=c-1;
if(x==p) {if((c/5)*5!=0) fo<<(c/5)*5<<"\n"; else fo<<"1\n"; break; }
}
if(x!=p) fo<<"-1\n";
fo.close();
return 0;
}
