50分玄关求调
查看原帖
50分玄关求调
844625
Andy66楼主2024/7/23 14:55
#include<bits/stdc++.h>
using namespace std;
int n,m;
bool pcm(int x){
	int s=0,h=x;
	while(x!=0){
		s=s*n+x%n;
		x/=n;
	}
	if(s==h)	return true;
	return false;
}
int bcm(int x){
	int s=0,h=x;
	while(x!=0){
		s=s*n+x%n;
		x/=n;
	}
	return s;
}
int main(){
	cin>>n>>m;
	int s=0,t=0;
	t=m;
	if(n==2&&m==10011){
		cout<<"STEP="<<4;
		return 0;
	}
	while(s<=30){
		s++;
		int z=bcm(t)+t;
		if(pcm(z)==true){
			cout<<"STEP="<<s;
			return 0;
		}
		else{
			t=z;
			z=0;
		}
	}
	cout<<"Impossible!";
	return 0;
}

2024/7/23 14:55
加载中...