Cod sursa(job #1472301)

Utilizator adiXMGemene Adrian adiXM Data 16 august 2015 22:03:48
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <fstream>
using namespace std;
ifstream f("fact.in");
ofstream g("fact.out");
long long p;
inline int Count(int n){

    int cnt=0;
    while(n)
    {
        cnt+=n/5;
        n/=5;
    }
    return cnt;
}
inline void Search(){

    int st=1,dr=100000000000,m,ans=-1;
    while(st<=dr)
    {
        m=(st+dr)/2;
        if(Count(m)<p)
        {
            st=m+1;
        }
        else
            dr=m-1;
    }
    if(Count(st)==p)
        g<<st;
    else
        g<<"-1";
}
int main()
{
    f>>p;
    Search();
    return 0;
}