- 回文数
- 2017-07-17 15:27:19 @
#include<bits/stdc++.h>
using namespace std;
string s;
int a[10005];
int jz,len;
int plus_(int n){
int carry=0;
int c[10005]={0};
for(int i=0;i<n;i++){
c[i]=a[i]+a[n-i-1]+carry;
if(c[i]>=jz){
c[i]=c[i]%jz;
carry=1;
}
else carry = 0;
//cout<<c[i]<<" ";
}
if(carry==1){
n++;
c[n-1]=1;
}
//cout<<c[n-1];
for(int i=0;i<n;i++){
a[i]=c[i];
}
return n;
}
bool judge(int a[]){
for(int i=0;i<len/2;i++){
if(a[i]!=a[len-i-1]) return false;
}
return true;
}
int main(){
cin>>jz>>s;
len = s.size();
for(int i=0;i<len;i++){
if(s[i]-'0'<10) a[i]=s[i]-'0';
else if(s[i]-'A'<=5) a[i]=s[i]-'A'+10;
}
//len = plus_(len);
int cnt=0;
while(cnt<=30){
if(judge(a)){
cout<<"STEP="<<cnt<<endl;
return 0;
}
else{
cnt++;
len = plus_(len);
//print();
}
}
cout<<"Impossible"<<endl;
return 0;
}
1 条评论
-
cucrui LV 7 @ 2017-07-17 22:34:45
我傻逼了,“Impossible!”要加感叹号》——《
- 1