2 条题解

  • 0
    @ 2025-12-16 14:26:58

    模拟

    如果 m=1m=1,那么无论提升多少次,温度都是 11 ,所以只需要升温 11 次就行。

    如果是其他温度,那么升温次数肯定不会超过 3030 ,所以接下来按题目描述模拟即可,但是要注意别爆精度。

    时间复杂度 O(logn)O(logn)

    #include<bits/stdc++.h>
    
    using namespace std;
    
    int main(){
        int T = 1;
        cin >> T;
        while(T--){
            int n, m;
            cin >> n >> m;
            if(m == 1){
                cout << 1 << endl;
                continue;
            }
            auto ans = pair(1ll * abs(n - m), 1);
            auto t = 1ll * m;
            int k = 1;
            while(1){
                t *= m;
                k++;
                ans = min(ans, {abs(t - n), k});
                if(t >= n) break;
            }
            cout << ans.second << endl;
        }
    }
    
    

    信息

    ID
    159
    时间
    1000ms
    内存
    256MiB
    难度
    4
    标签
    递交数
    125
    已通过
    17
    上传者