代码
#include<bits/stdc++.h>
using namespace std;
int t,n;
bool zs(int x){
if(x==2){
return 1;
}
for(int i=1;i<=sqrt(x);i++){
if(x%i==0){
return 0;
}
}
return 1;
}
struct node{
int sum;
string s;
};
void bfs(int sum,string s){
queue<node>q;
q.push({sum,s});
while(!q.empty()){
node now=q.front();
q.pop();
if(now.sum>n){
continue;
}
if(now.sum==n){
cout<<s;
return;
}
if(sum==0){
q.push({sum+2,s+"1"});
q.push({sum+5,s+"2"});
q.push({sum+5,s+"3"});
q.push({sum+4,s+"4"});
q.push({sum+5,s+"5"});
q.push({sum+6,s+"6"});
q.push({sum+3,s+"7"});
q.push({sum+7,s+"8"});
q.push({sum+6,s+"9"});
}else{
q.push({sum+6,s+"0"});
q.push({sum+2,s+"1"});
q.push({sum+5,s+"2"});
q.push({sum+5,s+"3"});
q.push({sum+4,s+"4"});
q.push({sum+5,s+"5"});
q.push({sum+6,s+"6"});
q.push({sum+3,s+"7"});
q.push({sum+7,s+"8"});
q.push({sum+6,s+"9"});
}
}
}
int main(){
// freopen("sticks.in","r",stdin);
// freopen("sticks.out","w",stdout);
cin>>t;
while(t--){
cin>>n;
if(n==1){
cout<<-1;
continue;
}
if(zs(n)&&n>=7){
cout<<-1;
continue;
}
string s="";
bfs(0,s);
}
return 0;
}
蒟蒻求调