/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 1ms 328.0 KiB
#3 Accepted 2ms 440.0 KiB
#4 Accepted 2ms 320.0 KiB
#5 Accepted 2ms 576.0 KiB
#6 Accepted 5ms 576.0 KiB
#7 Accepted 39ms 1.879 MiB
#8 Accepted 34ms 1.527 MiB
#9 Accepted 37ms 1.645 MiB
#10 Accepted 45ms 2.293 MiB
#11 Accepted 43ms 2.066 MiB

Code

#include<bits/stdc++.h>

using namespace std;
#define ll long long
#define int ll
# define double long double
const int N = 2e5 + 2, MOD = 1e9 + 7;
#define deb(x) cout<<#x<<"="<<x<<endl;
#define F first
#define S second
int n, k;

int ternary_search(int l, int r) {
    while (l <= r) {
        int m1 = l + (r - l) / 3;
        int m2 = r - (r - l) / 3;
        int f1 = (k - (m1 * n)) * m1;      //evaluates the function at m1
        int f2 = (k - (m2 * n)) * m2;      //evaluates the function at m2
        if (f1 < f2)
            l = m1 + 1;
        else
            r = m2 - 1;
    }
    return (k - (l * n)) * l;
}


void solve() {
    cin >> n >> k;
    if (n >= k) {
        cout << 0;
        return;
    }
    cout << ternary_search(0, k / n);


}

signed main() {
    ios_base::sync_with_stdio(false);
    cout.tie(NULL);
    cin.tie(NULL);
//#ifndef ONLINE_JUDGE
//    freopen("output.txt", "w", stdout);
//    freopen("input.txt", "r", stdin);
//#endif
    int tt = 1;
    cin >> tt;
    for (int i = 0; i < tt; i++) {
//        cout << "Case " << i + 1 << ": ";
        solve();
        cout << "\n";
    }
}

Information

Submit By
Type
Submission
Problem
P1092 Bitwise AND
Contest
Brain Booster #5
Language
C++20 (G++ 13.2.0)
Submit At
2024-09-05 17:24:41
Judged At
2024-10-03 13:04:23
Judged By
Score
100
Total Time
45ms
Peak Memory
2.293 MiB