Cod sursa(job #2704930)

Utilizator mitocaru_marioMitocaru Mario-Alexandru mitocaru_mario Data 11 februarie 2021 17:07:05
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.76 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long st=1,dr=99999999999999999,rez,mid,val;
long long verifica(long long n)
{
    long long x=5,y=0;
    while(n/x>0)
    {
        y=y+n/x;
        x=x*5;

    }
    return y;

}
int main()
{
    f>>rez;
    if(rez==0)
    {
        g<<1;
        return 0;
    }
    while(st<=dr)
    {
        mid=(st+dr)/2;
        val=verifica(mid);
        cout<<val<<" ";
        if(val>rez)
            dr=mid-1;
        if(val<rez)
            st=mid+1;
        cout<<st<<" "<<dr<<endl;
        if(val==rez)
        {
            while(mid%5!=0)mid--;
            g<<mid;
            return 0;
        }

    }
    g<<-1;
}