Cod sursa(job #32552)

Utilizator RobytzzaIonescu Robert Marius Robytzza Data 18 martie 2007 00:57:58
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include<fstream.h>
#include<process.h>
int main(){
ifstream fin("fact.in");
ofstream fout("fact.out");
long long P,nr=0,S=1,k=0;
fin>>P;
if (P==0) {
fout<<1;
fin.close();}
while (nr!=P){
   S=S%100;
    for (short i=1;i<=10;i++){
	 S*=i;
	 k++;
	 if (S%10==0){
	      S/=10;
	      nr++;}
	 if (nr==P) {
	    if (P>2)
	       k--;
	    fout<<k;
	    fout.close();
	 exit(0);
	    }}
	    if (k>9)
	       k--;}
fout<<k;
fin.close();
fout.close();
return 0;
}