Python programming solution to a problem [Blue Bridge Cup official website] DAY12- algorithm exam training

Questions algorithm to train a large number of completely equal to the minimum square of n

Resource limitation
time limit: 1.0s memory limit: 256.0MB
problems described
  a large output is equal to the smallest perfect square of n.
  If the number can be expressed in the form of a square of a natural number, the called number is a perfect square
  Tips: Note that the range of the data
input format of
  an integer n
output format
  large as the smallest perfect square of n
sample input
71711
Sample Output
71,824
data size conventions and
  n is a 32-bit signed integer

while True:
    try:
        n = int(input())
        if n<=0:
            print(0)
            break
        else:
            m = n**0.5
            if int(m)*int(m) == n:
                print(int(m)*int(m))
            else:
                print(int((m+1))*int((m+1)))
    except:
        break

Published 577 original articles · won 137 Like · views 40000 +

Guess you like

Origin blog.csdn.net/weixin_43838785/article/details/104340274