社区讨论

50分玄关求调

P1015[NOIP 1999 普及组] 回文数参与者 1已保存回复 0

讨论操作

快速查看讨论及其快照的属性,并进行相关操作。

当前回复
0 条
当前快照
1 份
快照标识符
@lyy2djee
此快照首次捕获于
2024/07/23 14:58
2 年前
此快照最后确认于
2024/07/23 15:37
2 年前
查看原帖
CPP
#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;
}

回复

0 条回复,欢迎继续交流。

正在加载回复...