Cod sursa(job #2079500)

Utilizator cyg_ionutStan Ionut Gabriel cyg_ionut Data 1 decembrie 2017 14:28:16
Problema GFact Scor 15
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.54 kb
#include <bits/stdc++.h>
using namespace std;

using i64 = long long;

int n, b, e;

int fun(int x, int n) {
    int ans = 0;
    while (x / n > 0) {
        ans = ans + x / n;
        x = x / n; }
    return ans; }

int main() {
    freopen("gfact.in", "r", stdin);
    freopen("gfact.out", "w", stdout);
    int ans = 0;

    scanf("%d %d", &b, &e);

    for (i64 bit = 1LL << 30; bit > 0; bit = bit / 2)
        if (fun(bit + ans, b) < e)
            ans = ans + bit;
    ans+= 1;
        printf("%d\n", ans);

    return 0; }