Petya非常喜欢幸运数字。每个人都知道幸运数字是正整数,其十进制记录只包含幸运数字4和7。例如,数字47、744、4是幸运的,而5、17、467则不是。 Petya调用正整数n的掩码,该掩码是在从左到右连续写入数字n的所有幸运数字后获得的数字。例如,数字72174994的掩码是数字7744,掩码7是7,掩码9999047是47。显然,任何数字的掩码总是一个幸运数字。 Petya有两个数字-一个任意整数a和一
Input
唯一一行包含两个整数a和b(1 ≤ a,b ≤ 10e5). 保证数字b是幸运的。
Output
在唯一的一行中打印一个数字-Petya所寻求的数字c。
Sample 1
Inputcopy | Outputcopy |
---|---|
1 7 | 7 |
Sample 2
Inputcopy | Outputcopy |
---|---|
100 47 | 147 |
个幸运数字b。帮助他找到最小数字c(c > a) 使得数字c的掩码等于b。
#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<stack>
#include<string.h>
#include<algorithm>
#include<map>
#include<cstring>
#include<queue>
#include<set>
#include<stdlib.h>
using namespace std;
typedef long long ll;
//#define dbug cout<<"hear!"<<erndl;
const int N = 1e6 + 5, INF = 0x3f3f3f3f;
int n, m;
ll gcdd(ll a, ll b)
{
if (b) while ((a %= b) && (b %= a));
return a + b;
}
//ll h[N], w[N], e[N], ne[N], idx;//h数组存储的永远都是a的第一条边的编号;ne数组存储的是编号为i边的下一条编号;邻接表类似于链表;
//int idx, h[N],ans;
//int dis[30005],flag[N];
//bool book[30005];
//int brr[N];
//int arr[150][150];
//struct node
//{
// int a, b, w;
// int next;
//}e[N];
//
//
//
//void add(int a, int b, int c)
//{
// e[idx].a = a;
// e[idx].b = b;
// e[idx].w = c;
// e[idx].next = h[a];
// h[a] = idx++;
//}
//
//
//int dijs(int a, int b)
//{
// memset(dis, INF, sizeof(dis));
// memset(book, false, sizeof book);
// dis[0] = 0;
// for (int i = 0;i < n;i++)
// {
// int t = -1;
// for (int j = 0;j <= n;j++)
// {
// if (!book[j] && (t == -1 || dis[t] > dis[j]))
// {
// t = j;
// }
// }
// book[t] = true;
// for (int j = 1;j <= n;j++)
// {
// if (flag[j] <= b && flag[j] >= a)
// {
// dis[j] = min(dis[j], dis[t] + arr[t][j]);
// }
// }
// }
// return dis[1];
//}
int par[N];
int arr[6];
int brr[N];
int crr[N];
struct node
{
int a, b, w;
}nodee[N];
void init()
{
for (int i = 0;i <= n;i++)
{
par[i] = i;
}
}
bool cmp(node a, node b)
{
return a.w < b.w;
}
int findd(int x)
{
if (par[x] != x)
{
par[x] = findd(par[x]);
}
return par[x];
}
int xx(int x)
{
int cnt = 0;
for (;x > 0;x /= 10)
{
if (x % 10 == 4 || x % 10 == 7)//此处判断是否4或者7
{
cnt = cnt * 10 + x % 10;
}
}
return cnt;
}
int main()
{
int a, b;
cin >> a >> b;
b = xx(b);
a++;
while (xx(a) != b)a++;
cout << a;
return 0;
}