首先记录下来,然后二分。注意暴longlong的坑点
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int t ,cnt;
const int maxn=1e6+10;
ll a[maxn];ll n;
void dfs(ll num,int sa,int sb){
if(sa+sb>=20) return ;
if(sa==sb&&(sa!=0)){
a[cnt++]=num;
}
dfs(num*10+4,sa+1,sb);
dfs(num*10+7,sa,sb+1);
}
int main(){
cin>>t;cnt=0;
dfs(0,0,0);
sort(a,a+cnt);
// cout<<" = = = = == "<<a[cnt-1]<<endl;
cout<<" cnt = "<<cnt<<endl;
// for(int i=0;i<20;i++){
// cout<<a[i]<<" " ;
// }
// cout<<endl;
while(t--){
scanf("%lld",&n);
int ans=lower_bound(a,a+cnt,n)-a;
if(ans==cnt){
puts("44444444447777777777");
}
else{
cout<<" ans = "<<ans<<endl;
cout<<a[ans]<<endl;
}
//\cout<<"ans = "<<a[ans]<<endl;
}
}