알고리즘
[알고리즘] Sherlock and Squares
혀나Lee
2019. 7. 18. 17:47
해커랭크 문제. Sherlock and Squares
- 링크: https://www.hackerrank.com/challenges/sherlock-and-squares/problem
- Author: darkshadows
- Difficulty: Easy
문제 요약: a, b 포함 사이의 수중 제곱수의 개수를 찾아라.
#!/bin/python3
import math
import os
import random
import re
import sys
# Complete the squares function below.
def squares(a, b):
count = 0
import math
n = a
while n <= b:
r = math.sqrt(n)
int_r = int(r)
if int_r == r:
count += 1
int_r += 1
n = int_r * int_r
return count
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
q = int(input())
for q_itr in range(q):
ab = input().split()
a = int(ab[0])
b = int(ab[1])
result = squares(a, b)
fptr.write(str(result) + '\n')
fptr.close()