Submission #65922009


Source Code Expand

#include <bits/stdc++.h>
#define all(c) c.begin(), c.end()
#define sz(c) ll(c.size())
#define ll long long
#define tr(a, it) for (auto it = a.begin(); it != a.end(); it++)
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c), x) != c.end())
#define vi vector<int>
#define vll vector<ll>
#define vvll vector<vll>
#define vpii vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define pll pair<ll, ll>
#define inf 1e9
#define MOD 1000000007
#define MAXN 10000
#define madar 1e18
#define moda 998244353
#define loop(i, s, e) for (ll i = s; i < e; i++)
#define revloop(i, s, e) for (ll i = s; i >= e; i--)
#define newl cout << endl
#define pb push_back
#define f first
#define s second

using namespace std;

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

ll gcd(ll a, ll b) {
    if (!(a % b)) return b;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
    return (a / gcd(a, b)) * b;
}

ll MSB(ll n) {
    ll ans = -1;
    while (n) {
        ans++;
        n /= 2;
    }
    return ans;
}

ll power(ll a, ll b, ll mod) {
    ll p = 1;
    a %= mod;
    while (b > 0) {
        if (b & 1)
            p = (p * a) % mod;
        a = (a * a) % mod;
        b >>= 1;
    }
    return p;
}

ll inv_mod(ll n, ll mod) {
    return power(n, mod - 2, mod);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// #ifdef LOCAL
// #include "debug.h"
// #endif

ll N = 65;
vll fact(N + 1, 0);

void facto() {
    fact[0] = fact[1] = 1;

    for (ll i = 2; i <= N; i++) {
        fact[i] = (fact[i - 1] * i) % moda;
    }
}

ll nCr(ll n, ll r) {
    if (n < r || r < 0) return 0;
    ll numerator = fact[n];
    ll denominator = (fact[r] * fact[n - r]) % moda;
    return (numerator * inv_mod(denominator, moda)) % moda;
}

void solve(int tc) {
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    ll a = 0;

    ll pop = __builtin_popcountll(n);
    if (pop == k) {
        ans = n % moda;
    }

    for (ll b = 0; b < 62; b++) {
        if (n & (1ll << b)) {
            a++;

            ll rem = k - (pop - a);
            if (rem <= 0 || b < rem) continue;

            ll kk = ((1ll << b) - 1) % moda;
            ll pp = nCr(b - 1, rem - 1);
            ans = (ans + (kk * pp) % moda) % moda;

            ll hp = (n >> (b + 1)) << (b + 1);
            hp %= moda;
            ll kl = nCr(b, rem);
            ans = (ans + (kl * hp) % moda) % moda;
        }
    }

    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);

    facto();

    int t = 1;
    cin >> t;
    int tc = 0;
    while (t--) {
        tc++;
        solve(tc);
    }

    return 0;
}

Submission Info

Submission Time
Task E - Popcount Sum 3
User arikrrr77
Language C++ 20 (gcc 12.2)
Score 0
Code Size 2977 Byte
Status WA
Exec Time 2 ms
Memory 3636 KiB

Compile Error

Main.cpp: In function ‘void solve(int)’:
Main.cpp:88:16: warning: unused parameter ‘tc’ [-Wunused-parameter]
   88 | void solve(int tc) {
      |            ~~~~^~

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 0 / 450
Status
AC × 1
AC × 3
WA × 31
Set Name Test Cases
Sample example_00.txt
All example_00.txt, hand_00.txt, hand_01.txt, hand_02.txt, random_00.txt, random_01.txt, random_02.txt, random_03.txt, random_04.txt, random_05.txt, random_06.txt, random_07.txt, random_08.txt, random_09.txt, random_10.txt, random_11.txt, random_12.txt, random_13.txt, random_14.txt, random_15.txt, random_16.txt, random_17.txt, random_18.txt, random_19.txt, random_20.txt, random_21.txt, random_22.txt, random_23.txt, random_24.txt, random_25.txt, random_26.txt, random_27.txt, random_28.txt, random_29.txt
Case Name Status Exec Time Memory
example_00.txt AC 1 ms 3416 KiB
hand_00.txt AC 1 ms 3636 KiB
hand_01.txt AC 1 ms 3564 KiB
hand_02.txt WA 1 ms 3476 KiB
random_00.txt WA 2 ms 3480 KiB
random_01.txt WA 2 ms 3636 KiB
random_02.txt WA 1 ms 3412 KiB
random_03.txt WA 2 ms 3560 KiB
random_04.txt WA 1 ms 3352 KiB
random_05.txt WA 1 ms 3476 KiB
random_06.txt WA 1 ms 3404 KiB
random_07.txt WA 1 ms 3420 KiB
random_08.txt WA 2 ms 3424 KiB
random_09.txt WA 1 ms 3632 KiB
random_10.txt WA 1 ms 3508 KiB
random_11.txt WA 2 ms 3416 KiB
random_12.txt WA 1 ms 3564 KiB
random_13.txt WA 1 ms 3512 KiB
random_14.txt WA 1 ms 3504 KiB
random_15.txt WA 1 ms 3572 KiB
random_16.txt WA 1 ms 3508 KiB
random_17.txt WA 1 ms 3564 KiB
random_18.txt WA 1 ms 3484 KiB
random_19.txt WA 1 ms 3476 KiB
random_20.txt WA 1 ms 3552 KiB
random_21.txt WA 1 ms 3480 KiB
random_22.txt WA 1 ms 3512 KiB
random_23.txt WA 1 ms 3476 KiB
random_24.txt WA 1 ms 3428 KiB
random_25.txt WA 1 ms 3416 KiB
random_26.txt WA 1 ms 3472 KiB
random_27.txt WA 1 ms 3364 KiB
random_28.txt WA 1 ms 3476 KiB
random_29.txt WA 1 ms 3424 KiB