Cod sursa(job #2075400)

Utilizator MaligMamaliga cu smantana Malig Data 25 noiembrie 2017 13:36:11
Problema Factorial Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.94 kb
#include <iostream>
#include <fstream>
#include <queue>
#include <cstdlib>

#if 1
#define pv(x) cout<<#x<<" = "<<x<<"; ";cout.flush()
#define pn cout<<endl
#else
#define pv(x)
#define pn
#endif

using namespace std;
ifstream in("fact.in");
ofstream out("fact.out");

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mp make_pair
const int NMax = 2e5 + 5;
const int mod = 666013;

ll P;

ll getNr(ll);

int main() {
    in>>P;

    ll pw = 1,pos = 0,lim = 1e9;
    for (;pw <= lim; pw <<= 1) ;
    pw >>= 1;

    while (pw) {
        if (getNr(pos+pw) < P) {
            pos += pw;
        }

        pw >>= 1;
    }

    if (getNr(pos+1) == P) {
        out<<pos+1;
    }
    else {
        out<<"-1\n";
    }

    return 0;
}

ll getNr(ll nr) {
    ll ans = 0;

    ll pw = 5;
    while (pw <= nr) {
        ans += nr / pw;
        pw *= 5;
    }

    return ans;
}