Cod sursa(job #2257585)

Utilizator pepsiM4A1Ozturk Arif pepsiM4A1 Data 10 octombrie 2018 10:59:32
Problema Factorial Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <cstdio>
using namespace std;
int numar5(int x)
{
    int res=x/5;
    int p=25;
    while(p<=x)
    {
        res+=(x/p);
        if(x/p<5) break;
        p*=5;
    }
    return res;
}
int main()
{
    freopen ("fact.in","r",stdin);
    freopen ("fact.out","w",stdout);
    int p;
    scanf("%d",&p);
    int ans=0,st=0,dr=500000000;
    while(st<=dr)
    {
        int mij=(st+dr)/2;
        int functie=numar5(mij);
        if(functie==p)
        {
            ans=mij;
            dr=mij-1;
        }
        else if(functie>p)
        {
            dr=mij-1;
        }
        else st=mij+1;
    }
    printf("%d\n",ans);
}