Cod sursa(job #2377749)
| Utilizator | Data | 11 martie 2019 03:10:38 | |
|---|---|---|---|
| Problema | Factorial | Scor | 95 |
| Compilator | cpp-64 | Status | done |
| Runda | Arhiva de probleme | Marime | 0.63 kb |
#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;
}
