/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 320.0 KiB
#2 Accepted 1ms 508.0 KiB
#3 Accepted 2ms 324.0 KiB
#4 Accepted 2ms 564.0 KiB
#5 Accepted 2ms 484.0 KiB
#6 Accepted 5ms 588.0 KiB
#7 Accepted 38ms 1.922 MiB
#8 Accepted 35ms 1.602 MiB
#9 Accepted 37ms 1.777 MiB
#10 Accepted 42ms 2.328 MiB
#11 Accepted 41ms 2.199 MiB

Code

#include <bits/stdc++.h>

using namespace std;
using i64 = long long;

void solve() {
    i64 n, k; cin >> n >> k;
    auto f = [&] (i64 m) {
        return (k - m * n) * m;
    };
    i64 l = -1, r = k / n + 1;
    while (r - l > 1) {
        i64 m = l + (r - l) / 2;
        if (f(m) < f(m + 1)) l = m;
        else r = m;
    }
    cout << (k - r * n) * r << '\n';
}

signed main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr);
    i64 T; cin >> T;
    while(T--) solve();
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1092 Bitwise AND
Language
C++17 (G++ 13.2.0)
Submit At
2024-10-03 17:59:44
Judged At
2024-11-11 02:45:15
Judged By
Score
100
Total Time
42ms
Peak Memory
2.328 MiB