Cod sursa(job #2431523)

Utilizator blotucosmincosmin blotucosmin Data 19 iunie 2019 20:51:46
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.71 kb
#include<bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
unsigned long long st,dr,mij,x,n;
unsigned long long verif(unsigned long long limit)
{
    unsigned long long ct=0,p=5,i;
    while(p<=limit)
    {
        ct+=limit/p;
        p*=5;
    }
    return ct;
}
int main()
{
    fin>>n;
    if(n==0)
    {
        fout<<1;
        return 0;
    }
    st=1;
    dr=5*n;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        x=verif(mij);
        if(x==n)
        {
            while(mij%5!=0) mij--;
            fout<<mij<<"\n";
            return 0;
        }
        if(x>n) dr=mij-1;
        else st=mij+1;
    }
    fout<<-1;
    return 0;
}