Cod sursa(job #2988432)

Utilizator popuPop Matei Tudor popu Data 4 martie 2023 13:34:34
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <bits/stdc++.h>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

#define f first
#define s second

long long p,m,st=1,dr=(1<<31)-1,c,rez=-1;
pair<int,int> v[500000];

int d5(int a)
{
    c=0;
    for(int i=5;i<=a;i*=5)
        c+=(a/i);
    return c;
}

int cb(int a)
{
    while(st<=dr)
    {
        m=(st+dr)/2;
        c=d5(m);
        if(c==p)
            rez=m,dr=m-1;
        else if(c<p)
            st=m+1;
        else if(c>p)
            dr=m-1;
    }
    return rez;
}

int main()
{
    fin>>p;
    if(!p)
        fout<<1;
    else
        fout<<cb(p);
    return 0;
}