Algorithm/PS

[BOJ/백준] 9724 - Perfect Cube [python]

chanwoong1 2023. 3. 27. 10:25
728x90

문제 링크

 

9724번: Perfect Cube

A perfect cube is an integer whose cube root is also an integer. For example 1, 8, 27, 64, 125, etc. are examples of perfect cubes but 9, 25 and 113 are not. Given two positive integers A and B, your task is to calculate the number of perfect cubes in the

www.acmicpc.net

문제 풀이

두 입력값 A와 B 사이의 완전 세제곱수의 갯수를 출력해준다.

정답 코드

for i in range(1, int(input()) + 1) :
    A, B = map(int, input().split())
    cnt = 0
    x = 1
    while x ** 3 <= B :
        if x ** 3 >= A : cnt += 1
        x += 1
    print(f"Case #{i}: {cnt}")
728x90