Cod sursa(job #1725972)
| Utilizator | Data | 6 iulie 2016 20:54:01 | |
|---|---|---|---|
| Problema | Factorial | Scor | 80 |
| Compilator | cpp | Status | done |
| Runda | Arhiva de probleme | Marime | 1.75 kb |
#include <fstream>
using namespace std;
ifstream fin ("fact.in");
ofstream fout ("fact.out");
long long p;
int main()
{
int n=6, n1=0, v=25, v1=1, x, x1, x2, v2;
fin>>p;
while(p>n)
{
n1=n;
n=5*n+1;
v1=v;
v=v*5;
}
x2=n-1;
v2=v;
if(p==n)
fout<<v;
else
{
while(n!=p and n1!=p)
{
x2=x2/5;
v2=v2/5;
x=x2;
x1=v2;
n=n-1;
while(n!=(n1+x))
{
n1=n1+x;
v1=v1+x1;
n=n-x;
v=v-x1;
if(n1>p)
{
n1=n1-x;
v1=v1-x1;
}
if(n<p)
{
n=n+x;
v=v+x1;
}
if(n==p)
{
fout<<v;
break;
}
if(n1==p)
{
fout<<v1;
break;
}
if(n==n1)
{
fout<<-1;
break;
}
}
}
}
return 0;
}
/*
int main()
{
int x=5, ct=0;;
fin>>p;
while(p<=x)
{
x=x-ct;
x=x*5;
ct++;
x=x+ct;
}
if(p==x)
{
x=x-ct;
x=x*5;
fout<<x;
}
else
{
if(p<x-ct)
fout<<-1;
else
{
x=x-ct;
ct=x-p;
x=x*5;
x=x-(5*);
fout<<x;
}
}
return 0;
}
*/
