Problem Set 6(Heterosquare)

Heterosquare numbers are the numbers having “n” digits such that the  last n digits of the square of the number will not be the number itself. .Write an algorithm and the subsequent Python code to check if the given number is a Heterosquare number. Write a function to find the square of a given number. For example, 22 is a 2 digit heterosquare number with a square of 484 and 111 with its  square  12321, is a 3 digit heterosquare number.

Input Format
First line contains the number to be checked

Output Format
Print Heterosquare  or Not Heterosquare

Input:
The number

Processing Involved:
def heterosquare(n):
    length = len(str(n))
    if n != int(str(n**2)[-length:]):
        print('Heterosquare')
    else:
        print('Not Heterosquare')

Output:
Display whether the number is heterosquare or not

Program:
def heterosquare(n):
    length = len(str(n))
    if n != int(str(n**2)[-length:]):
        print('Heterosquare')
    else:
        print('Not Heterosquare')

n = int(input())
heterosquare(n)

Algorithm:
Step1. Define the function heterosquare with one parameter n
Step1.1 assign temp as an empty string and length as length of the number n
Step1.2 check if the last n digits of the square of n is not the number n if true the display heterosquare else display not heterosquare
Step2. get the number n
Step3. Call the function heterosquare to check if n is heterosquare or not
Step4. End

No comments:

Post a Comment

Bonus Practice Problems(GMT To IST)

IST (Indian Standard Time) is 5 hours 30 minutes ahead of GMT(Greenwich Mean Time). Develop an algorithm and write the Python code to find...