CF355A.Vasya and Digital Root
普及-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Vasya has recently found out what a digital root of a number is and he decided to share his knowledge with you.
Let's assume that S(n) is the sum of digits of number n, for example, S(4098) = 4 + 0 + 9 + 8 = 21. Then the digital root of number n equals to:
- dr(n) = S(n), if S(n) < 10;
- dr(n) = dr( S(n) ), if S(n) ≥ 10.
For example, dr(4098) = dr(21) = 3.
Vasya is afraid of large numbers, so the numbers he works with are at most 101000. For all such numbers, he has proved that dr(n) = S( S( S( S(n) ) ) ) (n ≤ 101000).
Now Vasya wants to quickly find numbers with the given digital root. The problem is, he hasn't learned how to do that and he asked you to help him. You task is, given numbers k and d, find the number consisting of exactly k digits (the leading zeroes are not allowed), with digital root equal to d, or else state that such number does not exist.
瓦西娅最近了解了数字根(digital root)的概念,他决定与你分享这一知识。
假设 $ S(n) $ 表示数字 $ n $ 的各位数字之和,例如 $ S(4098) = 4 + 0 + 9 + 8 = 21 $。那么数字 $ n $ 的数字根定义为:
- 若 $ S(n) < 10 $,则 $ dr(n) = S(n) $;
- 若 $ S(n) \geq 10 $,则 $ dr(n) = dr(S(n)) $。
例如,$ dr(4098) = dr(21) = 3 $。
瓦西娅害怕大数,因此他所处理的数字至多为 $ 10^{1000} $。对于所有这样的数字,他已证明:当 $ n \leq 10^{1000} $ 时,恒有
dr(n)=S(S(S(S(n))))。
现在瓦西娅希望快速找出具有给定数字根的数字。但问题在于,他尚未学会如何做到这一点,于是请求你的帮助。你的任务是:给定整数 $ k $ 和 $ d $,找出一个恰好由 $ k $ 位数字组成(不允许前导零)且其数字根等于 $ d $ 的数字;若不存在这样的数字,则说明其不存在。
输入格式
The first line contains two integers k and d (1 ≤ k ≤ 1000; 0 ≤ d ≤ 9).
第一行包含两个整数 k 和 d(1 ≤ k ≤ 1000;0 ≤ d ≤ 9)。
输出格式
In a single line print either any number that meets the requirements (without the leading zeroes) or "No solution" (without the quotes), if the corresponding number does not exist.
The chosen number must consist of exactly k digits. We assume that number 0 doesn't contain any leading zeroes.
在一行中输出任意一个满足要求的数(不能有前导零),或者如果不存在满足条件的数,则输出“No solution”(不带引号)。
所选数字必须恰好由 k 位数字组成。我们规定数字 0 不含任何前导零。
输入输出样例
输入#1
4 4
输出#1
5881
输入#2
5 1
输出#2
36172
输入#3
1 0
输出#3
0
说明/提示
For the first test sample dr(5881) = dr(22) = 4.
For the second test sample dr(36172) = dr(19) = dr(10) = 1.
对于第一个测试样例,dr(5881)=dr(22)=4。
对于第二个测试样例,dr(36172)=dr(19)=dr(10)=1。
输入解题思路,AI测评打分。不知道怎么写?