Cod sursa(job #658506)

Utilizator catatoaCatalin Toader catatoa Data 8 ianuarie 2012 22:49:22
Problema Factorial Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.39 kb
#include <fstream>
using namespace std;

int main(){
ifstream fin("fact.in");
ofstream fout("fact.out");
long long p,nr,f,m;
fin>>p;
if(p==0){
  fout<<1;
  fout.close();
  return 0;
}
nr=p*5;
f=25;
while(f*5<=nr)
  f*=5;
while(f<=nr && f>5){
  m=f;
  while(m<nr){
    /*if(m==nr){
      fout<<-1;
      fout.close();
      return 0;
    }*/
    nr-=5;
    m+=f;
  }
  f/=5;
}
fout<<nr;
fout.close();
}