Cod sursa(job #485373)

Utilizator falselightbogdan horia-daniel falselight Data 18 septembrie 2010 10:48:59
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.63 kb
#include <fstream>
#include <cmath>

#define MAXPOWER 8

using namespace std;

int i;

unsigned int factorial (unsigned int N){
    unsigned int p = N;

    if (N == 1)
        return 1;
    else{
        p *= factorial (N - 1);
        return p;
    }
}

int countZeros (int a){
    for (i = MAXPOWER; i >= 0; --i)
        if (a % (unsigned int)pow (10, i) == 0)
            return i;
    return -1;
}

int main(){
    ifstream fin ("fact.in");
    ofstream fout ("fact.out");

    int P;
    fin >> P;

    for (i = 0; i < pow (10, MAXPOWER); ++i)
        if (countZeros (factorial (i)) == P)
            break;

    fout << i;

    return 0;
}