Cod sursa(job #2266829)

Utilizator aalexxdinu@gmail.comDinu Alexandra [email protected] Data 22 octombrie 2018 21:49:30
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.6 kb
#include <iostream>
#include <fstream>
using namespace std;



int nrzero (int x)
{
    int nr=0;
    while (x>=5)
    {
        nr+=x/5;
        x/=5;
    }
    return nr;
}

int fact (int P)
{
    int r=0, pas=1<<28;
    while (pas!=0)
    {
        if (nrzero (r+pas)<P)
            r+=pas;
        pas/=2;
    }
    return 1+r;
}

ifstream in("fact.in");
    ofstream out("fact.out");


int main()
{
    int a,P;

    in>>P;

    a= fact (P);
    if (nrzero (a)!=P)
        out<< -1;
    else
        out<< a;
    in.close ();
    out.close ();

    return 0;
}