https://www.acmicpc.net/problem/14913
14913번: 등차수열에서 항 번호 찾기
k가 몇 번째 항인지 출력한다. 만약, k가 주어진 a와 d로 만들어진 등차수열의 수가 아니면 "X"를 출력한다.
www.acmicpc.net
1 2 3 4 5 6 7 8 9 10 11 | def sol(a, d, k): if (k - a) % d == 0 and (k - a) // d >= 0: return (k - a) // d + 1 else: return 'X' if __name__ == '__main__': a, d, k = map(int, input().split()) print(sol(a, d, k)) | cs |
반응형
'python-algorithm' 카테고리의 다른 글
leetcode 2697. Lexicographically Smallest Palindrome (1) | 2023.12.28 |
---|---|
leetcode 2828. Check if a String Is an Acronym of Words (0) | 2023.12.28 |
leetcode 2928. Distribute Candies Among Children I (0) | 2023.12.27 |
leetcode CodeTestcaseTestcaseTest Result2942. Find Words Containing Character (0) | 2023.12.27 |
leetcode 2951. Find the Peaks (0) | 2023.12.27 |
댓글