C. Bewitching Stargazer solution

แชร์
ฝัง
  • เผยแพร่เมื่อ 28 ธ.ค. 2024

ความคิดเห็น • 2

  • @computerknowledge4217
    @computerknowledge4217  23 ชั่วโมงที่ผ่านมา

    C.
    In C++ language
    #include
    using namespace std;

    pair computeLucky(long long left, long long right, int threshold) {
    if (right - left + 1 < threshold) {
    return {0, 0};
    }

    if (right - left + 1 == 1) {
    return {left, 1};
    }

    long long mid = left + (right - left) / 2;
    if ((right - left + 1) % 2) {
    pair leftResult = computeLucky(left, mid - 1, threshold);

    long long totalLucky = mid + 2 * leftResult.first + mid * leftResult.second;
    int totalSegments = 2 * leftResult.second + 1;
    return {totalLucky, totalSegments};
    } else {
    pair leftResult = computeLucky(left, mid, threshold);

    long long totalLucky = 2 * leftResult.first + mid * leftResult.second;
    int totalSegments = 2 * leftResult.second;
    return {totalLucky, totalSegments};
    }
    }
    int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int test_cases;
    cin >> test_cases;
    while (test_cases--) {
    long long n, k;
    cin >> n >> k;

    pair result = computeLucky(1, n, k);

    cout

  • @computerknowledge4217
    @computerknowledge4217  23 ชั่วโมงที่ผ่านมา

    Like and Subscribe guys..👍