A9237 | Vasya and Digital Root
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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:
1. $dr(n)=S(n)$ , if $S(n)<10$ ;
2. $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 $10^{1000}$ . For all such numbers, he has proved that $dr(n)=S(S(S(S(n))))$ $(n<=10^{1000})$ .
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.
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:
1. $dr(n)=S(n)$ , if $S(n)<10$ ;
2. $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 $10^{1000}$ . For all such numbers, he has proved that $dr(n)=S(S(S(S(n))))$ $(n<=10^{1000})$ .
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.
输入格式
The first line contains two integers $k$ and $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.
The chosen number must consist of exactly $k$ digits. We assume that number 0 doesn't contain any leading zeroes.
输入输出样例
输入 #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$ .
For the second test sample $dr(36172)=dr(19)=dr(10)=1$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted