CF2109C2 题解

· · 题解

我们小学二年级就学过,如果一个数是 9 的倍数,那么它的各位数字和也是 9 的倍数。
故我们先 mul 9,此时数字的范围是 9 \sim 9 \times 10^9
digit,此时数字的范围是 9 \sim 819 的倍数,因为最大是 10^9 - 1
digit,就得到了 9
此时我们再 add n - 9 就好了。
由于此题是交互题,会有 ILEIdleness limit exceeded)的情况:

  1. 不能用 \n!因为 \n 不刷新缓冲区!
  2. 记得输入!(好像没有人会犯这么弱智的错误)
#include <bits/stdc++.h>
using namespace std;
#define ll long long
ll T, n, t;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    cin >> T;
    while(T--){
        cin >> n;
        cout << "mul 9" << endl; cin >> t;
        cout << "digit" << endl; cin >> t;
        cout << "digit" << endl; cin >> t;
        cout << "add " << n - 9 << endl; cin >> t;
        cout << "!" << endl; cin >> t;
    }
    return 0;
}

提交记录 326376947