Cod sursa(job #2210004)

Utilizator MatteoalexandruMatteo Verzotti Matteoalexandru Data 5 iunie 2018 13:53:50
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <fstream>

using namespace std;
ifstream in ("fact.in");
ofstream out ("fact.out");
int cif0(int n)
{
    int zero=0;
    long long p5=5;
    while(p5<=n)
    {
        zero=zero+n/p5;
        p5*=5;
    }
    return zero;
}
int main()
{
    int p;
    long long st=1,dr,mij;
    in>>p;
    dr=5*p;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        if(cif0(mij)<p)
            st=mij+1;
        else
            dr=mij-1;
    }
    if(cif0(st)==p)
        out<<st;
    else out<<-1;
    return 0;
}