Cod sursa(job #112192)

Utilizator larion_octavianLarion Octavian-Stefan larion_octavian Data 3 decembrie 2007 18:11:45
Problema Factorial Scor 30
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.49 kb
#pragma option -3 -r -Z -O2 -a
#include<fstream.h>


int chestie(int p)
{
register unsigned long n,x=5,m;
short sw=0;
n=p; m=p;

while(sw==0)
 {
 if(m/x) n=n+m/x,x*=5;
 else sw=1;
 }
return n;
}

int main()
{

ifstream f("fact.in");
ofstream h("fact.out");
register unsigned long p,n,m;
f>>p;
if(p==0) h<<1;
else {
n=chestie(p);
m=p;

if(n==p) h<<n*5;
 else {while(n>p)
       n=chestie(--m);
       if(n==p)	h<<m*5;
       else h<<(m+1)*5;
      }
}
return 0;
}