Cod sursa(job #2666643)

Utilizator JaguarKatStere Teodor Ioanin JaguarKat Data 2 noiembrie 2020 11:45:54
Problema Factorial Scor 5
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.65 kb
#include <iostream>
#include <fstream>

using namespace std;

ifstream fin("fact.in");
ofstream fout("fact.out");

int cate_zerouri_are_factorial_de(int n)
{
    int nr = 0;
    int putere5 = 1;
    while(n)
    {
        putere5 *= 5;
        nr += n / putere5;
        n /= 5;
    }
    return nr;
}

int main()
{
    int p,n,step,pos = -1;
    fin >> p;
    step = 1 << 30;
    while(step > 0)
    {
        if(cate_zerouri_are_factorial_de(pos + step) < p)pos += step;
        step /= 2;
    }
    if(cate_zerouri_are_factorial_de(pos + 1) == p)
    {
        fout << pos + 1;
    }
    else fout << -1;
    return 0;
}