Python basic algorithm training - function and recursion (51~55)
51. Palindromic square numbers
[title description]
Palindromic numbers refer to numbers that are the same when read from left to right and from right to left. For example, 12321 is a typical palindrome number.
Given a base B (2≤B≤20, expressed in decimal), output all the numbers greater than or equal to 1 and less than or equal to 300 (in decimal) whose square is a palindromic number when expressed in base B. Use A, B... to represent 1010, 1111, etc.
[Input]
A total of one line, a single integer B (B is expressed in decimal).
[Output]
Each line has two B-ary numbers that meet the requirements, the second number is the square of the first number, and the second number is a palindrome.
[Input example]
10
[Output example]
1 1
2 4
3 9
11 121
22 484
26 676
101 10201
111 12321
121 14641
202 40804
212 44944
264 69696
def tenToM(n,m):
s=""
while n:
if n%m<10:
s=chr(n%m+ord('0'))+s
else:
s=chr(n%m-10 + ord('A'))+s
n//=m
return s
def is_Hw(s):
l=len(s)
for i in range(l//2):
if s[i]!=s[l-1-i]:
return False
return True
m=int(