Cod sursa(job #3195537)

Utilizator verde.cristian2005Verde Flaviu-Cristian verde.cristian2005 Data 21 ianuarie 2024 10:36:02
Problema Factorial Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.66 kb
#include <bits/stdc++.h>
using namespace std;

#ifndef ACASA
    ifstream in("fact.in");
    ofstream out("fact.out");
    #define cin in
    #define cout out
#endif

int zeros(int n)
{
    int rez = 0;
    while(n)
    {
        rez += n / 5;
        n /= 5;
    }
    return rez;
}

int main()
{
#ifdef ACASA
    freopen("test.in", "r", stdin);
    freopen("test.out", "w", stdout);
#endif
    int p;
    cin >> p;
    int r = 0, pas = 1 << 30;
    while(pas)
    {
        if(zeros(r + pas) < p)
            r += pas;
        pas /= 2;
    }
    if(zeros(r + 1) == p)
        cout << r + 1;
    else
        cout << -1;
    return 0;
}