Cod sursa(job #1103922)

Utilizator terrorturtle01Ion George Mihai terrorturtle01 Data 10 februarie 2014 09:32:44
Problema Factorial Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.46 kb
#include <fstream>
using namespace std;

int zero(int k){
    long m, z;
    m = 5;
    z = 0;
    while(k/m != 0){
        z+=k/m;
        m *= 5;
    }
    return z;
}

int main()
{
    int P, nrz = 1;
    long N;
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>P;
    N = 1;
    while(nrz != P){
        nrz = zero(N);
        if(nrz < P){
            N++;
        }else{
            N--;
        }
    }
    N++;
    g<<N;
}