Cod sursa(job #2401951)

Utilizator Ioana_CioboteaCiobotea Ioana Ioana_Ciobotea Data 10 aprilie 2019 11:05:16
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.62 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int nrz(int n)
{
    int s = 0, pp = 5;
    while(n >= pp)
    {
        s += n / pp;
        pp = pp * 5;
    }
    return s;
}

int cautbin(int a)
{
    int p = 1, u = 100000000, poz = 0;
    while(p <= u)
    {
        int m = (p + u) / 2;
        int nz = nrz(m);
        if(a == nz)
            poz = m;
        if(a <= nz)
            u = m - 1;
        else
            p = m + 1;
    }
    return poz;
}
int main()
{
    int P;
    f >> P;
    g << cautbin(P);
    return 0;
}