Pagini recente » Cod sursa (job #2271069) | Cod sursa (job #1429427) | Cod sursa (job #1303987) | Cod sursa (job #673729) | Cod sursa (job #2377749)
#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;
cautare();
return 0;
}