Update With Mod and Big Numbers
Python
Hard
2 views
Problem Description
Read q operations on x starting with 0. Operations are ADD v, MUL v, and MOD m. Values can be large. Use big integers safely and output final x.
Input Format
First line q. Next q lines: op value.
Output Format
One integer x.
Sample Test Case
Input:
5
ADD 999999999999999999
MUL 2
MOD 1000
ADD 7
MUL 3
Official Solution
import sys
lines=sys.stdin.read().splitlines()
if not lines or not lines[0].strip():
sys.exit(0)
q=int(lines[0].strip())
x=0
for i in range(1,1+q):
parts=(lines[i] if i<len(lines) else '').split()
if not parts: continue
op=parts[0]
v=int(parts[1])
if op=='ADD':
x+=v
elif op=='MUL':
x*=v
else:
m=v
if m!=0:
x%=m
sys.stdout.write(str(x))
Solutions (0)
No solutions submitted yet. Be the first!
No comments yet. Start the discussion!