Cod sursa(job #1460644)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 13 iulie 2015 13:52:34
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.67 kb
#include <iostream>
#include <fstream>
using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");
inline int nr0(int n)
{
    int nr=0;
    while(n > 0) {
        nr = nr + n/5;
        n = n/5;
    }
    return nr;
}
inline int caut_bin(int p)
{
    int st=1;
    int dr=(1 << 30);
    int mij;
    int ans=-1;
    while(st<=dr)
    {
        mij=(st+dr)/2;
        int aux = nr0(mij);
        if(aux<p)
            st=mij+1;
        else if(aux>=p) {
            dr=mij-1;
            if(aux == p)
                ans = mij;
        }
    }
    return ans;
}
int main()
{
    int p;
    in>>p;
    out<<caut_bin(p);
    return 0;
}