300769: CF146B. Lucky Mask

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Lucky Mask

题意翻译

Petya很喜欢幸运的数字。 当一个数的每一位都是4或者7,那么这个数字就是幸运的。 比如47,744,4都是幸运数字; 5,17,467都不是。 Petya 定义一个数的“面罩”为:这个数从高位到低位每一位4或者7拼起来的数(好难翻译啊,不懂就看一下例子)。比如72174994的“面罩”就是7744,9999047的"面罩"就是47,7的“面罩”就是7。很显然,一个数的“面罩“一定是一个幸运数字。 Petya有两个数,a(一个任意的正整数),b(一个幸运数字)。 问您求:[最小的,且比a大的一个“面罩”为b的数c]。 样例解释:当a=100,b=47时:c为147。因为c的“面罩”必须为47且要大于100,所以最小的这样的数就是147了。

题目描述

Petya loves lucky numbers very much. Everybody knows that lucky numbers are positive integers whose decimal record contains only the lucky digits 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not. Petya calls a mask of a positive integer $ n $ the number that is obtained after successive writing of all lucky digits of number $ n $ from the left to the right. For example, the mask of number $ 72174994 $ is number $ 7744 $ , the mask of $ 7 $ is $ 7 $ , the mask of $ 9999047 $ is $ 47 $ . Obviously, mask of any number is always a lucky number. Petya has two numbers — an arbitrary integer $ a $ and a lucky number $ b $ . Help him find the minimum number $ c $ $ (c>a) $ such that the mask of number $ c $ equals $ b $ .

输入输出格式

输入格式


The only line contains two integers $ a $ and $ b $ $ (1<=a,b<=10^{5}) $ . It is guaranteed that number $ b $ is lucky.

输出格式


In the only line print a single number — the number $ c $ that is sought by Petya.

输入输出样例

输入样例 #1

1 7

输出样例 #1

7

输入样例 #2

100 47

输出样例 #2

147

Input

题意翻译

Petya很喜欢幸运的数字。 当一个数的每一位都是4或者7,那么这个数字就是幸运的。 比如47,744,4都是幸运数字; 5,17,467都不是。 Petya 定义一个数的“面罩”为:这个数从高位到低位每一位4或者7拼起来的数(好难翻译啊,不懂就看一下例子)。比如72174994的“面罩”就是7744,9999047的"面罩"就是47,7的“面罩”就是7。很显然,一个数的“面罩“一定是一个幸运数字。 Petya有两个数,a(一个任意的正整数),b(一个幸运数字)。 问您求:[最小的,且比a大的一个“面罩”为b的数c]。 样例解释:当a=100,b=47时:c为147。因为c的“面罩”必须为47且要大于100,所以最小的这样的数就是147了。

加入题单

算法标签: