Cod sursa(job #2000274)

Utilizator alextodoranTodoran Alexandru Raul alextodoran Data 13 iulie 2017 12:04:55
Problema Factorial Scor 55
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.48 kb
#include <iostream>
#include <fstream>
using namespace std;
int p,l,r,m;
int vczalf(int n)
{
    int k=0;
    while(n>0){k+=n/5; n/=5;}
    return k;
}
int main()
{
    ifstream fin ("fact.in");
    ofstream fout ("fact.out");
    fin>>p;
    l=1;
    r=500000000;
    int best=-1;
    while(l<r)
    {
        m=(l+r)/2;
        if(vczalf(m)>=p){best=m;r=m-1;}
        else l=m+1;
    }
    if(vczalf(best)==p)fout<<best;
    else fout<<"-1";
    return 0;
}