http://hackerrank.com/challenges/smart-number/problem?isFullScreen=true
Smart Number | HackerRank
Find if a number has even number of factors.
www.hackerrank.com
import math
def is_smart_number(num):
val = int(math.sqrt(num))
if num / val == val:
return True
return False
for _ in range(int(input())):
num = int(input())
ans = is_smart_number(num)
if ans:
print("YES")
else:
print("NO")
핵심은 약수가 홀수면 무조건 제곱수인 것이다.
따라서 if num / val == 1:을 if num / val == val : 또는 if val**2 == num 과 같은 형식으로 바꿔주면 된다.
'파이썬 코딩테스트 > 해커랭크' 카테고리의 다른 글
| HackerRank / The Love-Letter Mystery / Python (0) | 2021.12.26 |
|---|---|
| HackerRank / Missing Number / Python (0) | 2021.12.26 |
| HackerRank / Sherlock and Array / Python (0) | 2021.12.24 |
| HackerRank / Sherlock and Cost / Python (0) | 2021.12.24 |
| HackerRank / The Maximum Subarray / Python (0) | 2021.12.22 |