ROOTSQR Editorial

PROBLEM LINK:

Practice
Contest

Author: Baban Gain
Tester: Baban Gain
Editorialist: Baban Gain

DIFFICULTY:

CAKEWALK

PREREQUISITES:

Sorting

PROBLEM:

Given a number N, find it’s Integral square root (if exist) S and check if the difference N-S^2 within X percentage of N.

EXPLANATION:

Negative numbers can not have a real square root!.
Hence, when N is negative, print no

why?

You should print yes only when the program returns it’s square root S and N-S^2 within X percentage of N.

Otherwise, calculate difference D = N-S^2
if D \leq \frac{X*N}{100}, print yes
else print no

SOLUTIONS:

Setter's Solution
import math
T, X = map(int, input().split())
for z in range(T):
    N = int(input())
    if N < 0:
        print("no")
        continue
    S = int(math.sqrt(N))
    if N - (S ** 2) <= 0.01 * X * N:
        print("yes")
    else:
        print("no")

Link to Solution