Pagini recente » Cod sursa (job #3264201) | Cod sursa (job #574723) | Cod sursa (job #2311994) | Cod sursa (job #1319850) | Cod sursa (job #2377750)
#include <iostream>
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int p;
int v;
int a[500];
int ridicare(int x)
{
int r=1,p=5;
while(x!=0){
if(x%2==1)r=r*p;
p=p*p;
x=x/2;
}
return r;
}
bool t=true;
int cautare()
{
long long s1=0;
long long s;
while(p>0){s=0;
v=0;
while(5*s+1<=p){v++;
s=5*s+1;
}
if(p/s>=5){
g<<"-1";t=false;
break;
}
else{
s1=s1+(p/s)*ridicare(v);
p=p-s*(p/s);
}
}
if(t==true)g<<s1;
}
int main()
{
f>>p;
if(p==0)g<<1;
else
cautare();
return 0;
}