AcWing 1346. 回文平方
原题链接
简单
作者:
wjie
,
2021-01-13 14:53:25
,
所有人可见
,
阅读 314
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
void work(int x, int n)
{
int y = x * x;
vector<int> vec2;
while (y)
{
vec2.push_back(y % n);
y /= n;
}
for (int i = 0; i < vec2.size()/2; ++i)
{
if (vec2[i] != vec2[vec2.size()-1-i]) return;
}
vector<int> vec1;
while (x)
{
vec1.push_back(x % n);
x /= n;
}
for (int i = vec1.size()-1; i >= 0; --i)
{
if (vec1[i] < 10) printf("%d", vec1[i]);
else printf("%c", vec1[i]-10+'A');
}
printf(" ");
for (int i = vec2.size()-1; i >= 0; --i)
{
if (vec2[i] < 10) printf("%d", vec2[i]);
else printf("%c", vec2[i]-10+'A');
}
puts("");
}
int main()
{
int n;
scanf("%d", &n);
for (int i = 1; i <= 300; ++i) work(i, n);
return 0;
}