Cod sursa(job #29977)

Utilizator accxelAlex Carp accxel Data 12 martie 2007 00:48:48
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<fstream>
#include<math.h>
using namespace std;
long int fact(long int x)
{
        long int i,prod=1;
        for(i=1;i<=x;i++)
                prod=prod*i;
        return prod;
}
int main()
{
        long int n=1,prod,i,p,gasit=0;
        ifstream f("fact.in");
        ofstream g("fact.out");
        f>>p;
        while(n<=pow(10,p/2)){
                prod=fact(n);
		i=pow(10,p);
                if((prod%i)%10!=0){
                        gasit=1;
			g<<n;
		}
                else
                        n++;
        }
        if(!gasit)
		g<<"-1";
        f.close();
        g.close();
        return 0;
}