Cod sursa(job #1462758)
Utilizator | Data | 18 iulie 2015 21:05:30 | |
---|---|---|---|
Problema | Factorial | Scor | 5 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.69 kb |
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int main(){
long long n,i,j,s=1,p=-5,h=1,x=0,cnt=-1;
in>>n;
if(n==25)
{
out<<"-1";
return 0;
}
long long aux;
aux=n;
aux=aux*5;
if(n==0)
{
out<<"1";
return 0;
}
for(i=1;i<=100000000;i++)
{
s=s*5;
cnt++;
x=x+cnt;
p=p+cnt*5;
if(aux>s)
{
out<<aux;
return 0;
}
if(n>=(s-x-cnt)/5 && n<(s-x)/5)
{
out<<"-1";
return 0;
}
if(aux<s)
{
aux=aux-p;
}
}
}