Cod sursa(job #2070254)

Utilizator DovlecelBostan Andrei Dovlecel Data 19 noiembrie 2017 13:08:41
Problema Factorial Scor 95
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;
const int L=30;
int nrzero(int nr)
{
    int nrz=0;
    while(nr>0)
    {
        nrz=nrz+nr/5;
        nr=nr/5;
    }
    return nrz;
}
int main()
{
    long long p,pas;
    int r;
    ifstream f("fact.in");
    ofstream g("fact.out");
    f>>p;
    if(p==0)
        g<<1;
    else
    {
        r=0;
        pas=1<<L;
        while(pas!=0)
        {
            if(nrzero(r+pas)<p)
                r=r+pas;
            pas=pas/2;
        }
    }
    r++;
    if(nrzero(r)==p)
        g<<r;
    else
        g<<-1;
    return 0;
}