Source Code
#include <bits/stdc++.h>
using namespace std;

#define IAMSPEED ios_base::sync_with_stdio(0); cin.tie(0);

const int mod = 998244353;
const int oo = 1000000010;
const int N = 200010;

void solve(){
    string str; 
    int y, need = 0; 
    cin >> str >> y;
    for(int i = 0; i < (int)str.size(); ++i){
        need = ((long long)need * 10 + str[i] - '0') % y;
    }
    if(need == 0){
        cout << str << '\n';
        return; 
    }
    reverse(str.begin(), str.end());
    need = y - need;
    bool carry = false; 
    for(int i = 0; need > 0 || carry; ++i){
        if(i == (int)str.size()) str.push_back('0');
        int x = str[i] - '0' + carry + need % 10;
        carry = (x >= 10);
        str[i] = x % 10 + '0';
        need /= 10; 
    }
    reverse(str.begin(), str.end());
    cout << str << '\n'; 
}

int main(){
    IAMSPEED
    int t = 1; 
    cin >> t;
    while(t--){
        solve();
    }
    return 0;
}
Copy
AZOZ with an O (Needs a Carry) ItsAboudTime
GNU G++17
162 ms
11.2 MB
Accepted