Accepted
Code
s = input().strip()
n = int(input().strip())
# Extract first two numbers from string
nums = []
tmp = ""
for c in s:
if c.isdigit():
tmp += c
elif c == '+':
if tmp:
nums.append(int(tmp))
tmp = ""
if tmp:
nums.append(int(tmp))
# First term and difference
st = nums[0]
diff = nums[1] - nums[0]
# Brute force summation
cnt = 0
total = 0
i = st
while cnt < n:
total += i
i += diff
cnt += 1
print(total)
Information
- Submit By
- Type
- Submission
- Problem
- P1231 Busy Friend
- Contest
- Testing - Intra LU Programming contest 25
- Language
- PyPy 3 (Python 3.9.18 PyPy 7.3.15)
- Submit At
- 2025-08-31 07:25:33
- Judged At
- 2025-08-31 07:25:33
- Judged By
- Score
- 100
- Total Time
- 64ms
- Peak Memory
- 18.297 MiB