Cod sursa(job #1253247)
| Utilizator | Data | 31 octombrie 2014 23:00:38 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.56 kb |
#include <iostream>
#include <fstream>
using namespace std;
long p;
int zero (int n)
{
long rez;
rez=0;
while(n>=5)
{
rez+=n/5;
n/=5;
}
return rez;
}
int main()
{
long i=0;
ifstream in("fact.in");
ofstream out("fact.out");
in>>p;
in.close();
long pas = 1<<30;
while (pas!=0)
{
if(zero(pas+i)<p)
i+=pas;
pas>>=1;
}
if(zero(i+pas+1)==p)
out<<i+1<<"\n";
else
out<<-1<<"\n";
out.close();
return 0;
}
