modular arithmetic in python

main.py
a = 5
b = 3
m = 7

# Addition
print((a + b) % m)  # Output: 1

# Subtraction
print((a - b) % m)  # Output: 2

# Multiplication
print((a * b) % m)  # Output: 1

# Division
print((a // b) % m)  # Output: 2

# Exponentiation
print(pow(a, b, m))  # Output: 6
255 chars
19 lines

related categories

gistlibby LogSnag