61分求助!
查看原帖
61分求助!
758211
zhangchenyi0509楼主2023/10/25 16:05
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int x;
int main()
{
	cin>>x;
	for (int i=1;i<=300;i++)
	{
		ll j=i*i;
		int cnt=0,s[100005];
		while (j>0)
		{
			cnt++;
			s[cnt]=j%x;
			j=j/x;
		}
		int t[100005];
		for (int k=cnt;k>0;k--)
		{
			t[k]=s[cnt+1-k];
		}
		bool flag=true;
		for (int k=1;k<=cnt;k++)
		{
			if (t[k]!=s[k])
			{
				flag=false;
				break;
			}
		}
		if (flag)
		{
			int c=i,co[100005],cn=0;
			while (c>0)
			{
				cn++;
				co[cn]=c%x;
				c=c/x;
			}
			for (int k=cn;k>0;k--)
			{
				cout<<co[k];
			}
			cout<<" ";
			for (int k=1;k<=cnt;k++)
			{
				cout<<s[k];
			}
			cout<<endl;
		}
	}
	return 0;
}
2023/10/25 16:05
加载中...