Cod sursa(job #2381631)

Utilizator vladadAndries Vlad Andrei vladad Data 17 martie 2019 11:13:55
Problema Factorial Scor 85
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include<bits/stdc++.h>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
int n, p, st, dr, mij, s, sol, c;
bool ok;
int main()
{
    f>>n;
    st=5;
    dr=400000015;
    while(st<=dr)
    {
        mij=(st+dr)>>1;
        p=5;
        c=mij;
        s=0;
        while(c/p)
        {
            s+=c/p;
            p=p*5;
        }
        if(s==n)
        {
            ok=1;
            break;
        }
        else if (s<n)
            st=mij+1;
        else
            dr=mij-1;
    }
    sol=mij-mij%5;
    g<<sol;
}