본문 바로가기
Beakjoon&프로그래머스/파이썬

[백준/파이썬] 9310번 Arithmetic and Geometric Sums

by 현장 2022. 10. 19.

-Code

while 1:
    n = int(input())
    if n == 0:
        break

    n1, n2, n3 = map(int, input().split())

    if n2 - n1 == n3 - n2:
        d = n2 - n1
        res = n * (2 * n1 + (n - 1) * d) // 2
    else:
        r = n2 // n1
        res = n1 * ((r ** n - 1) // (r - 1))
    print(res)

 n1 ** 0.5을 사용하니 zero division에러가 나서 다른 방법으로 하니 해결이 되었습니다.