Vasya and Digital Root

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.

Input
The first line contains two integers k and d (1 ≤ k ≤ 1000; 0 ≤ d ≤ 9).

Output
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.

Examples
Input
4 4

Output
5881

Input
5 1

Output
36172

Input
1 0

Output
0

Note
For the first test sample dr(5881)  =  dr(22)  =  4.
For the second test sample dr(36172)  =  dr(19)  =  dr(10)  =  1.

分析:只需要输出d和后面的一些‘0’就OK了。

代码如下:

#include"stdio.h"
#include"iostream"
int main()
{
	int k,d;
	while(~scanf("%d %d",&k,&d))
	{
		if(d==0&&k==1)
		{
			printf("0\n");
		}
		else if(d==0&&k>1)
		{
			printf("No solution\n");
		}
		else
		{
			printf("%d",d);
			for(int i=0;i<k-1;i++)
			{
				printf("0");
			}
		}
		printf("\n");
	}
	return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值