思路

根据题意,可以直接模拟。

每次 相当于除以 ,总共就需要 次模拟。

总共 次询问,在时间复杂度允许范围内。

小妙招

  • 有其他题解说卡精度的问题,这里只要过程中将 cdouble 即可,不用上高精度。
  • 低于向下取整,因为此处 始终非负,C++ 的除法 向零取整,也不用什么数学库。

直接上代码

#include <iostream>
#include <cmath>
using namespace std;

int main () {
    int tt; cin >> tt; while (tt--) {
        int n; double m; cin >> n >> m;
        int ans = 0;
        while (n) {
            int b = n * 100; double c = min(10000.0, b * (m - 1));
            n = b / 200; ans += b / 10; ans += c / 10;
        }
        cout << ans << endl;
    }
}