Cod sursa(job #1462076)
Utilizator | Data | 17 iulie 2015 00:33:56 | |
---|---|---|---|
Problema | Factorial | Scor | 10 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.57 kb |
#include <fstream>
#include <iostream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
int main()
{
long long n,k=1,i,f=0,h=5,x=1;
in>>n;
if(n==0)
{
out<<"1";
return 0;
}
for(i=1;k<=n;i++)
{
k=5*k;
if(k==n)
{
out<<"-1";
return 0;
}
if(k>n)
{
out<<n*5-f;
return 0;
}
f=f+x*h;
x++;
}
out<<"-1";
return 0;
}