Cod sursa(job #2068335)
| Utilizator | Data | 17 noiembrie 2017 16:45:32 | |
|---|---|---|---|
| Problema | Factorial | Scor | 100 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 0.62 kb |
#include <fstream>
using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
long long p;
bool putere (int a,int b)
{
long long s=0;
while(a)
{
a=a/5;
s+=a;
}
if(s<b)
return true;
return false;
}
bool puter (int a,int b)
{
long long s=0;
while(a)
{
a=a/5;
s+=a;
}
if(s==b)
return true;
return false;
}
int main()
{
long long k=0,pas=1<<30;
in>>p;
while(pas)
{
if(putere(k+pas,p))
k+=pas;
pas/=2;
}
if(puter(k+1,p))
out<<k+1;
else
out<<-1;
return 0;
}
