꾸준히 합시다

백준 파이썬 5101번: Sequences 본문

코딩 테스트 문제 풀이

백준 파이썬 5101번: Sequences

tturbo0824 2021. 7. 10. 13:27

https://www.acmicpc.net/problem/5101

 

5101번: Sequences

11 is the 5th term The sequence is –1, -4, -7, -10 (-1+ -3 = -4, -4 + –3 = -7, -7+ -3 = -10) -8 isn’t in the sequence.

www.acmicpc.net

문제 유형: 수학

 

 

# Solution 1

while True:
    start, dif, target = map(int, input().split())
    
    if start == dif == target == 0:
        break
    
    if ((dif > 0 and target <= start) or (dif < 0 and target >= start)):
        print('X')
    elif (target - start) % dif == 0:
        print((target - start) // dif + 1)
    else:
        print('X')

 

Comments