Cod sursa(job #1802595)

Utilizator acer18Herta Alina acer18 Data 10 noiembrie 2016 15:06:12
Problema Factorial Scor 60
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.74 kb
#include<iostream>
#include<fstream>
using namespace std;
ifstream fin("fact.in");
ofstream fout("fact.out");
long long n, p, min1 = 9999999999;
bool e;
 
bool ver(long long x)
{
    long long tot = 0;
    while(x)
    {
        tot += x / 5;
        x /= 5;
    }
    if(tot >= p)
    {
        if(tot == p) e = 1;
        return 1;
    }
    return 0;
}
 
void cautbin(long long  p, long long u)
{
    if(p <= u)
    {
        int mid = (p + u) / 2;
        if(ver(mid))
        {
            if(mid < min1) min1 = mid;
            cautbin(p, mid - 1);
        }
        else cautbin(mid + 1, u);
    }
}
 
int main()
{
    fin>>p;
 
    cautbin(1, 100000000);
 
    if(e) fout<<min1;
    else fout << "-1";
}