Cod sursa(job #284747)

Utilizator brainwashed20Alexandru Gherghe brainwashed20 Data 21 martie 2009 22:37:27
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include<stdio.h>
#include<math.h>
//#include<conio.h>

long put(long x)
{
 long k=0;
 while(x%5==0) { k++; x/=5; }
 return k;
}

int main()
{
 //clrscr();
 long p,i,t1,t2,k1,k2=0,k;
 freopen("fact.in","r",stdin);
 freopen("fact.out","w",stdout);
 scanf("%ld",&p);
 if(p==0) printf("1");
 else{
 for(i=1; k2<p; i++)
 {
  k2=(pow(5,i)-1)/4;
  t2=pow(5,i);
 }
 if(k2==p) printf("%ld",t2);
 else{
 t1=t2/5;
 k1=(pow(5,put(t1))-1)/4;
 if(p<(k1+k2)/2) k=t1+pow(5,p-k1);
	    else k=t2-pow(5,k2-p);
 printf("%ld",k);}}
 return 0;
}