constint N = 100000; intmain() { ios_base::sync_with_stdio(false); cin.tie(NULL); int t; cin >> t; while (t--) { LL x, y, k; cin >> x >> y >> k; do { LL noww = x / y; LL target = (noww + 1) * y; if (k+x <= target ) { x += k; k = 0; } else{ k -= target - x; x = target; } while(x%y==0){ x = x / y; }
} while (k > 0 && x> 1); if(x==1){ k %= (y - 1); // 这里,出错!数学要严谨! x += k; } cout << x << endl; }
intmain(){ ios::sync_with_stdio(false); cin.tie(0); int tt; cin >> tt; while (tt--) { int x, y, k; cin >> x >> y >> k; while (k > 0 && x > 1) { int rm = x % y; if (rm < y - 1) { int take = min(y - 1 - rm, k); x += take; k -= take; continue; } x += 1; while (x % y == 0) { x /= y; } k -= 1; } if (k > 0) { assert(x == 1); x = k % (y - 1) + 1; } cout << x << '\n'; } return0; }