Cod sursa(job #1520755)

Utilizator CobuzIonutCobuz Ionut-Alexandru CobuzIonut Data 9 noiembrie 2015 13:02:09
Problema Factorial Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.53 kb
#include <iostream>
#include<fstream>
#include<climits>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");

int nrz(int x)
{
    int p=5,nr=0;
    while(p<=x)
    {
        nr=nr+x/p;
        p=p*5;
    }
    return nr;
}

int main()
{
    int n,i,j,z,m,p,ok=0;
    cin>>p;
    i=1;
    j=INT_MAX;
    while(i<=j&&!ok)
    {
        m=(i+j)/2;
        z=nrz(m);
        if(z==p)ok=1;
        else if(z>p)j=m-1;
        else i=m+1;
    }
    if(ok)
        while(m%5!=0)m--;
    cout<<m;
}