Cod sursa(job #2765339)

Utilizator DordeDorde Matei Dorde Data 26 iulie 2021 14:59:53
Problema Pascal Scor 30
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.59 kb
#include <iostream>
#include <bitset>
#include <cstdio>
using namespace std;
int const N = 5e6 + 3;
int r , d , v [N] , p;
bitset <N> viz;
int fn (int x){
    if (viz [x])
        return v [x];
    p = d;
    while (p <= x)
        v [x] += x / p , p *= d;
    viz [x] = true;
    return v [x];
}
int main()
{
    freopen ("pascal.in" , "r" , stdin);
    freopen ("pascal.out" , "w" , stdout);
    scanf ("%d%d" , &r , &d);
    int ans = 0;
    for(int i = 0 ; i <= r ; ++ i)
        if (fn (r) > fn (r - i) + fn (i))
            ++ ans;
    printf ("%d" , ans);
    return 0;
}