Cod sursa(job #533152)
Utilizator | Data | 13 februarie 2011 12:19:50 | |
---|---|---|---|
Problema | Factorial | Scor | 85 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.43 kb |
#include<fstream>
#include<math.h>
using namespace std;
int s(int i)
{if(i==0) return 1;
else return (pow(5.0,double(i))+s(i-1));
}
int main()
{int p,n=0,i,j;
ifstream fin("fact.in");
fin>>p;
fin.close();
ofstream fout("fact.out");
do
{
i=0;
while(p>=s(i)) i++;
j=i-1;
n=n+pow(5.0,double(j));
p=p-s(j);
}while(p!=0);
if(n%5==0) {fout<<-1;return 0;}
n=n*5;
fout<<n;
fout.close();
return 0;
}