Cod sursa(job #2062311)

Utilizator cip_ionescuCiprian Ionescu cip_ionescu Data 10 noiembrie 2017 10:57:59
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.5 kb
#include <fstream>

using namespace std;

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

int zero(int n)
{
    int s = 0;
    while(n >= 5) s += (n /= 5);
    return s;
}

int main()
{
    ios_base::sync_with_stdio(false);
    int p, r, pas;
    unsigned long long n;
    fin >> p;
    r = 0;
    pas = 1 << 30;

    while(pas != 0){
        if(zero(r + pas) < p) r += pas;
        pas >>= 1;
    }

    if(zero(r + 1) == p) fout << r + 1;
    else fout << -1;

    return 0;
}