3_14 @ 2024-07-06 23:19:34
#include<bits/stdc++.h>
using namespace std;
using ll=unsigned long long;
const int MAX=1e5+1;
bool is_prime(string s){
int len=s.size();
for(int i=0;i<len/2;i++)
if(s[i]!=s[len-1-i])return false;
return true;
}
string to_dec(int base,string s){
int len=s.size(),ans=0,l=-1;
for(int i=len-1;i>=0;i--){
if('A'<=s[i]&&s[i]<='Z')ans+=((s[i]-'A'+10)*pow(base,++l));
else ans+=((s[i]-48)*pow(base,++l));
}
return to_string(ans);
}
string dec_to(string r,int base){
const int MAX=1111;
char str[MAX]={},ans[MAX]={};
ll o=-1,kf=0,num=stoll(r);
while(num>0){
kf=num%base;
if(kf>9)str[++o]=char('A'+num%base-10);
else str[++o]=char(48+num%base);
num/=base;
}
string ANS="";
for(int i=o-1;i>=0;i--)ANS+=str[i];
if(kf!=0)ANS=to_string(kf)+ANS;
return ANS;
}
string change(string s,int base){
string cnt=s;
reverse(cnt.begin(),cnt.end());
return dec_to(to_dec(base,cnt)+to_dec(base,s),base);
}
int n;
string m;
int main(){
cin>>n>>m;
ll len=m.size(),cnt=0;
bool flg=false;
while(cnt<31){
if(!is_prime(m))m=change(m,n);
else{
flg=true;
break;
}
cnt++;
}
if(flg)cout<<"STEP="<<cnt<<'\n';
else cout<<"Impossible\n";
return 0;
}
by SurperBoy @ 2024-07-07 10:34:11
用百度优先搜索
by tkm2013 @ 2024-07-07 16:51:46
@puyankunC2026 so
by SurperBoy @ 2024-07-07 17:22:33
?