Cod sursa(job #226518)
Utilizator | Mihalcea Ionut Alexandru Bortorix | Data | 1 decembrie 2008 21:14:16 |
---|---|---|---|
Problema | Factorial | Scor | 15 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include<fstream.h>
unsigned long st,dr,m,p,x,s;
void zero(int a){
unsigned long pw=5;
long c;
s=0;
while(pw<a){
c=a/pw;
s+=c;
pw*=5;}
}
void jumate(){
if(s>p){
dr=m;
m=(dr+st)/2;}
else if(s<p){
st=m;
m=(dr+st)/2;}
if(dr-st==1)m=dr;}
int main()
{ifstream fin("fact.in");
ofstream fout("fact.out");
st=1; dr=10000000;
m=(dr+st)/2;
fin>>p;
while(s!=p){
zero(m);
jumate();
}
if(m%5!=0)m-=m%5;
fout<<m;
fout.close();
fin.close();
return 0;
}