728x90
9310번: Arithmetic and Geometric Sums
The input will be given by 2 lines for each data set. The first line will be N, the term to which the sum should be computed. The next line of data is the series of numbers. They will be integers with a space separating each one. The series will be either
www.acmicpc.net
문제 풀이
입력값이 등차수열 혹은 등비수열일 경우에 따라 다른 조건으로 계산해준 뒤 출력해준다.
정답 코드
while True :
n = int(input())
if n == 0 : break
a, b, c = map(int, input().split())
if b - a == c - b : print(n * (2 * a + (n - 1) * (b - a)) // 2)
else : print(int(a * ((b / a) ** n - 1) / (b / a - 1)))
728x90
'Algorithm > PS' 카테고리의 다른 글
[BOJ/백준] 9325 - 얼마? [python] (0) | 2023.03.24 |
---|---|
[BOJ/백준] 9317 - Monitor DPI [python] (0) | 2023.03.24 |
[BOJ/백준] 9306 - Practice: Roll Call [python] (0) | 2023.03.24 |
[BOJ/백준] 9299 - Math Tutoring [python] (0) | 2023.03.24 |
[BOJ/백준] 9298 - Ant Entrapment [python] (0) | 2023.03.24 |