Cod sursa(job #2257067)

Utilizator XibronSomai Norbert-Attila Xibron Data 9 octombrie 2018 16:32:24
Problema Factorial Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <iostream>
#include <fstream>
#include <climits>

using namespace std;

long long int teszt(long long int number)
{
    int nulla=0, i=5;
    while(number/i!=0)
    {
        nulla += number/i;
        i*=5;
    }
    return nulla;
}

int main()
{
    freopen("fact.in", "rt", stdin);
    freopen("fact.out", "wt", stdout);
    int P, nulla;
    long long int e=1, u = LONG_MAX, number;
    cin>>P;
    if(P==0){cout<<1;return 0;}
    while(e!=u)
    {
        number = (e + u) / 2;
        nulla = teszt(number);
        if(nulla > P)
        {
            u = number;
        }
        else
        {
            e = number + 1;
        }
    }
    cout << e - 5;

    return 0;
}