Cod sursa(job #1268646)
Utilizator | FMI - Dan Nema priestnoob | Data | 21 noiembrie 2014 11:00:18 |
---|---|---|---|
Problema | Factorial | Scor | 20 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.67 kb |
#include<stdio.h>
#include<math.h>
using namespace std;
#define nmax 500000000
int n,p,c,v[20],k,i;
int main()
{
freopen("fact.in","r",stdin);
freopen("fact.out","w",stdout);
scanf("%d",&p);
if(p==0)
printf("1");
else
{
k=1;
i=1;
v[1]=1;
while(v[i]<100000000)
{
v[i+1]=v[i]*5+1;
i++;
}
i--;
int j=1;
while(p>5*v[j])
{
j++;
}
while(p>0)
{
if(p-v[j]<0)
j--;
p-=v[j];
n+=pow(5,j);
}
printf("%d",n);
}
}