Cod sursa(job #2379149)

Utilizator capmareAlexCapmare Alex capmareAlex Data 12 martie 2019 22:21:26
Problema Factorial Scor 50
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.58 kb
#include <bits/stdc++.h>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int power(long x)
{
    int s=0;
    int nr=5;
    if(x==0)return 1;
    while(x/nr)
    {
        s+=x/nr;
        nr*=5;
    }
    return s;
}
int main()
{   int p,sol;
    int low=0;
    long high=100000000;
    fin>>p;
    long middle;
    while(low<=high)
    {
        middle=(low+high)>>1;
        if(power(middle)>p)high=middle-1;
        else if(power(middle)<p)low=middle+1;
        else sol=middle,high=middle-1;
    }
    fout<<sol;
    return 0;
}