Cod sursa(job #2699606)

Utilizator Codrut112Codrut Copas Codrut112 Data 25 ianuarie 2021 10:05:23
Problema Factorial Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.73 kb
#include <fstream>
#include <iostream>
using namespace std;
ifstream f("factorial.in");
ofstream g("factorial.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;
}