Lũy thừa

View as PDF

Submit solution


Points: 0.17 (partial)
Time limit: 1.0s
Memory limit: 512M
Input: stdin
Output: stdout

Problem source:
NUS ACM Training
Problem types
Allowed languages
C, C++, Go, Java, Kotlin, Pascal, PyPy, Python, Rust, Scratch

Cho ~l~, ~r~ sao cho ~2 \leq l \leq r \leq 10^{12}~. Tìm số ~k~ nguyên dương lớn nhất sao cho tồn tại số nguyên dương ~x~ để ~l \leq x^k \leq r~.

Input

Dòng đầu tiên là số lượng test.

Mỗi dòng tiếp theo chứa hai số nguyên ~l, r~ biểu thị một test.

Output

Đối với mỗi test in ra "Case #" ~+~ số hiệu test ~+~ ": " ~+~ số ~k~ lớn nhất tìm được.

Sample Input

4
5 20
10 12
2 100
1000000000000 1000000000000

Sample Output

Case #1: 4
Case #2: 1
Case #3: 6
Case #4: 12

Comments

Please read the guidelines before commenting.



  • 2
    DAThinh_HuMaDa  commented on Jan. 20, 2026, 12:41 p.m.

    sử dụng hai chặt nhị phân chặt 1 tìm k chặt hai tìm x là ac


  • 1
    HoangNguyen2010  commented on Dec. 8, 2025, 1:46 p.m.

    chặt lồng


    • 0
      HoangNguyen2010  commented on Dec. 8, 2025, 1:46 p.m.

      chặt lần 1 là số mũ


    • 0
      HoangNguyen2010  commented on Dec. 8, 2025, 1:46 p.m.

      chặt lần 1 là số mũ


  • 3
    vominhmanh10  commented on Oct. 12, 2025, 10:41 a.m.

    với cơ số nhỏ nhất là 2 và giới hạn 1e12 thì k chỉ ở khoảng 60 trở xuống là cùng, ta duyệt k ngược cùng tìm kiếm nhị phân cơ số x sao cho x^k <= r rồi mới xét >= l cái đầu tiên thỏa cả hai chính là đáp án

    #include <bits/stdc++.h>
    using namespace std;
    using ll = long long;
    ll n, r, l, t = 1;
    ll check(ll mid, ll k) {
        ll res = 1;
        while (k--) {
            res *= mid;
            if (res > 1e12) return 0;
        }
        if (res <= r) return res;
        return 0;
    } 
    int main() {
        ios::sync_with_stdio(0);
        cin.tie(0); cout.tie(0);
        cin >> n;
        while (cin >> l >> r) {
            for (ll k = 64; k >= 1; k--) {
                ll lo = 2, hi = 1e12;
                ll res = 0;
                while (lo < hi) {
                    ll mid = (lo + hi + 1) / 2;
                    res = check(mid, k);
                    if (res > 0) lo = mid;
                    else hi = mid - 1;
                }
                if (check(lo, k) >= l) {
                    cout << "Case #" << t << ": " << k << "\n";
                    t++;
                    break;
                }
            }
        }
    }
    

  • -5
    nguyenmanhhung18092012  commented on Aug. 4, 2025, 1:30 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -5
    nguyenmanhhung18092012  commented on Aug. 4, 2025, 1:28 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -3
    ducbaothan  commented on July 23, 2025, 12:36 p.m. edited

    .


  • -9
    tienguyen3541  commented on Feb. 26, 2025, 2:23 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    minhtrivy09  commented on Aug. 7, 2024, 2:28 p.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • -6
      thaoq8861  commented on Sept. 7, 2024, 2:25 a.m.

      This comment is hidden due to too much negative feedback. Show it anyway.


  • -6
    huy_lovely  commented on Feb. 18, 2024, 10:31 a.m.

    This comment is hidden due to too much negative feedback. Show it anyway.


    • 2
      An212  commented on March 13, 2024, 3:00 p.m.

      l,r>=2 mà


  • 0
    baolam01662052827  commented on July 11, 2023, 6:06 p.m.

    Bài này có thể không cần giải bằng tìm kiếm nhị phân


  • -149
    hbphuc2009  commented on July 12, 2022, 1:05 a.m. edited

    This comment is hidden due to too much negative feedback. Show it anyway.


  • 17
    FuzZefer  commented on Sept. 1, 2021, 3:37 p.m.

    Câu này giới hạn test là bao nhiêu vậy ạ


    • 27
      leduykhongngu  commented on Sept. 30, 2021, 3:40 p.m.

      5000 test bạn nhé