Cod sursa(job #29958)

Utilizator accxelAlex Carp accxel Data 11 martie 2007 22:22:01
Problema Factorial Scor 5
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.73 kb
#include<fstream>
using namespace std;
int main()
{
        long int n=1,prod,p,i,cnt,gasit=0;
        ifstream f("fact.in");
        ofstream g("fact.out");
        f>>p;
        while(!gasit){
                cnt=0;
                prod=1;
                for(i=1;i<=n;i++)
                        prod=prod*i;
                for(i=1;i<=p;i++){
                        if(prod%10==0&&n!=0){
                                cnt++;
                                n/=10;
                        }
                        else
                                i=p;
                }
                if(cnt==p)
                        gasit=1;
                else
                        n++;
        }
        g<<n;
}