CHEFHW - Editorial

PROBLEM LINK:

Practice
Contest

Author: Adarsh Mandal

DIFFICULTY:

EASY

PREREQUISITES:

Math, Implementation

EXPLANATION:

The key observation is that the digital root of an integer k is the single-digit number 1 ≤ d ≤ 9 such that k \equiv d \mod 9.

You can prove this by noticing that 10^p \equiv 1 \mod 9 for all p.

Once we observe this, finding the k-th number is very simple .

SOLUTIONS:

Setter's Solution
#include<bits/stdc++.h>

using namespace std;
#define ll long long
int main() {
    int n;
    cin >> n;
    while (n--) {
        ll k, x;
        cin >> k >> x;
        cout << (9 * (k - 1)) + x << endl;
    }
}