#包括#包括#包括#包括#包括#包括使用命名空间标准;字符串cand=“”;字符串max_cand=“”;int inc_pos=0;int first_pos=0;整数和=101;int test_sum=0;int计数器=1;int e_pos=0;fstream输出1;整数inc(整数pos){cand[pos]++;坎迪[位置+1]--;}int生成(){int a=总和/9;int b=总和%9;cand+=字符(b+48);for(int q=0;q<a;q++){cand+='9';}max_cand=坎迪;max_cand[max_cand.length()-1]=cand[0];max_cand[0]=“9”;}int locate(){for(int a=0;a<cand.length()-1;a++){if(cand[a]!='9'){inc_pos=a;//cout<<inc_pos<<“”;}}}整型rev_loc(){for(int a=cand.length()-2;a>=0;a--)//向后搜索第一个非9{if(cand[a]!='9'){first_pos=a;a=0;//cout<<“还原为:”<<first_pos<<“”;}}}整型main(){整数步数=0;bool step_flag=true;cout<<“回文素数?”;cin>>总和;out1.open(“candidates.txt”,ios::out);cout<<“显示每个___名候选人。(0代表无,1代表全部,10代表10,等等)”<<endl;cout<<“警告:选择1将导致某些大素数的执行速度较慢。”<<endl;cin>>步骤;if(步骤==0){step_flag=假;}生成()//确定最低和最高候选人cout<<计数器<<“”<<cand<<endl;out1<<cand<<endl;坎德[0]++//增加到第二低候选(特殊情况)坎迪[1]——;计数器++;if(步骤==1){cout<<计数器<<“”<<cand<<endl;}输出1<<cand<<endl;而(cand<max_cand){而(cand[cand.length()-1]=='9')//我们正在迭代89次交换{locate();inc(inc_pos);计数器++;if(step_flag&&计数器%steps==0){cout<<计数器<<“”<<cand<<endl;}输出1<<cand<<endl;}rev_loc()//撤消所有交换cand[first_pos]++//增加最后一个非9数字cand[first_pos+1]=cand[cand.length()-1]//输入最后一个数字cand[first_pos+1]--;if(first_pos+1!=cand.length()-1){cand[cand.length()-1]=“9”//把最后9个放回去}计数器++;if(step_flag&&计数器%steps==0){cout<<计数器<<“”<<cand<<endl;}输出1<<cand<<endl;test_sum=0;}out1.关闭();cout<<“完成时间:”<<counter<<“”<<cand<<endl;_获取();}