Description
Lucky number is super lucky if it's decimal representation contains equal amount of digits 4 and 7. For example, numbers 47, 7744, 474477 are super lucky and 4, 744, 467 are not.
One day ztr came across a positive integer n. Help him to find the least super lucky number which is not less than n.
Input
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/b2776d768e6c22bb2cb38a592d3a2b78.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9f61591de1c8a8c5f8c7d228814838c5.png)
For each cases:
The only line contains a positive integer
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/7df305c950c9fa1d7448a36af4049dc3.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d145744987ffd848d7874a11151ad68e.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d11c95e88ab4c8b84819401a4bd9aa72.png)
![](https://i-blog.csdnimg.cn/blog_migrate/a22e580c04f29f0f25e4262eec591fd5.png)
![](https://i-blog.csdnimg.cn/blog_migrate/1b08ce66336b4f2b3a7b911c59c311d2.png)
![](https://i-blog.csdnimg.cn/blog_migrate/d9efe1ce21b2c8d4b2797ef8bce8879a.png)
![](https://i-blog.csdnimg.cn/blog_migrate/fa3622f4d030ec0876b2430626634fe7.png)
![](https://i-blog.csdnimg.cn/blog_migrate/9f61591de1c8a8c5f8c7d228814838c5.png)
Output
Output the answer
Sample Input
2 4500 47
Sample Output
4747 47
注意会爆long long 就算开无符号也只是两倍也会爆
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
typedef unsigned long long LL;
const int N = 100010;
LL num[N];
int k;
void dfs(int pos,int cnt1,int cnt2,LL sum)
{
if(pos>=19)
return ;
if(cnt1==cnt2&&cnt1+cnt2)
num[k++]=sum;
dfs(pos+1,cnt1+1,cnt2,sum*10+4);
dfs(pos+1,cnt1,cnt2+1,sum*10+7);
return ;
}
int main()
{
k=0;
dfs(0,0,0,0);
sort(num,num+k);
int t;
scanf("%d", &t);
while(t--)
{
LL x;
scanf("%I64u", &x);
int pos = lower_bound(num,num+k,x)-num;
if(pos==k)
printf("44444444447777777777\n");
else
printf("%I64u\n",num[pos]);
}
return 0;
}