CF1107B.Digital root

入门

通过率:0%

时间限制:1.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Today at the lesson of mathematics, Petya learns about the digital root.

The digital root of a non-negative integer is the single digit value obtained by an iterative process of summing digits, on each iteration using the result from the previous iteration to compute a digit sum. The process continues until a single-digit number is reached.

Let's denote the digital root of xx as S(x)S(x). Then S(5)=5S(5)=5, S(38)=S(3+8=11)=S(1+1=2)=2S(38)=S(3+8=11)=S(1+1=2)=2, S(10)=S(1+0=1)=1S(10)=S(1+0=1)=1.

As a homework Petya got nn tasks of the form: find kk-th positive number whose digital root is xx.

Petya has already solved all the problems, but he doesn't know if it's right. Your task is to solve all nn tasks from Petya's homework.

今天数学课上,佩佳学习了“数字根”的概念。

一个非负整数的数字根是指:通过反复对其各位数字求和(每次用上一次求和的结果继续进行各位数字求和),直至得到一个一位数为止,最终所得的这个一位数值即为该数的数字根。

我们用 S(x)S(x) 表示 xx 的数字根。例如:S(5)=5S(5)=5,S(38)=S(3+8=11)=S(1+1=2)=2S(38)=S(3+8=11)=S(1+1=2)=2,S(10)=S(1+0=1)=1S(10)=S(1+0=1)=1。

作为家庭作业,佩佳得到了 nn 道题目,每道题的形式均为:找出第 kk 个数字根为 xx 的正整数。

佩佳已经完成了所有题目,但他不确定答案是否正确。你的任务是求解佩佳家庭作业中的全部 nn 道题目。

输入格式

The first line contains a single integer nn (1≤n≤1031 \le n \le 10^3) — the number of tasks in Petya's homework. The next nn lines contain two integers kik_i (1≤ki≤10121 \le k_i \le 10^{12}) and xix_i (1≤xi≤91 \le x_i \le 9) — ii-th Petya's task in which you need to find a kik_i-th positive number, the digital root of which is xix_i.

第一行包含一个整数 nn(1≤n≤1031 \le n \le 10^3)—— 表示佩佳家庭作业中的任务数量。接下来的 nn 行每行包含两个整数 kik_i(1≤ki≤10121 \le k_i \le 10^{12})和 xix_i(1≤xi≤91 \le x_i \le 9)—— 表示佩佳的第 ii 个任务,要求找出数字根为 xix_i 的第 kik_i 个正整数。

输出格式

Output nn lines, ii-th line should contain a single integer — the answer to the ii-th problem.

输出 nn 行,第 ii 行应包含一个整数——即第 ii 个问题的答案。

输入输出样例

  • 输入#1

    3
    1 5
    5 2
    3 1

    输出#1

    5
    38
    19

输入解题思路,AI测评打分。不知道怎么写?

首页