Cod sursa(job #2470739)

Utilizator sandifx68Fazakas Alexandru sandifx68 Data 9 octombrie 2019 18:28:01
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.56 kb
#include <iostream>
#include <fstream>
using namespace std;

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

}
int main()
{
    ifstream f("fact.in");
    ofstream g("fact.out");
    int p;
    f>>p;
    int li=1,lf=2147483646;
    while(li<=lf)
    {
        int m=(li+lf)/2;
        int n0=nr0f(m);
        if(n0>=p)
            lf=m-1;
         else
            li=m+1;
    }
    if(nr0f(li)==p) g<<li;
     else g<<-1;
    f.close();
    g.close();
    return 0;
}