Rajesh has been challenge by his friend to find the number which have properties like,…
- User
Rajesh has been challenge by his friend to find the number which have properties like,
Here take no 12 such that square of 12(1212)=144 and 21 which is reverse of 12 have square(2121)= 441 whose reverse is equal to 144
and now Rajesh is not getting any way how to solve the problem.So he makes a list of the number and need your help to tell whether a reverse number exist for that or not,
'T' test case and 'N' number. 050 010000 INPUT The first line of input will be 'T' test case,follow by 'T' numbers
OUTPUT If reverse number exist for that print that number or otherwise print No.
SAMPLE INPUT 2 12 11
SAMPLE OUTPUT 21 No
Explanation
You have to print the number if the reverse number exist otherwise print No First number is 12 for this the reverse no is 21 whose square's reverse= square of 12 Second number is 11 for which no such number exist so print N0
Assistant
pythonT = int(input()) for _ in range(T): n = int(input()) r_str = str(n)[::-1].lstrip('0') r = int(r_str) if r_str else 0 n_sq = n ** 2 r_sq = r ** 2 reversed_r_sq = int(str(r_sq)[::-1]) if reversed_r_sq == n_sq and r != n: print(r) else: print("No")
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.