This page is still under construction.

Parts of this page are still being built. What you see may change.

Mod Arithmetic

Time limit1sMemory limit256 MB

Summary
Given A, B and C, print (A+B)%C, ((A%C)+(B%C))%C, (AxB)%C and ((A%C)x(B%C))%C on four lines.
Level

Easy1 of 10

Topics
Math
Solved
No attempts yet

Problem

You are given three numbers AA, BB, CC. Write a program that computes the following four values in order.

  1. (A + B) % C
  2. ((A % C) + (B % C)) % C
  3. (A × B) % C
  4. ((A % C) × (B % C)) % C

Here % is the remainder operator, so x % y is the remainder of xx divided by yy.

Input

The first line contains AA, BB, CC in that order, separated by spaces. (2≤A,B,C≤100002 \le A, B, C \le 10000)

Output

Print the four values on four lines, one per line. Print (A + B) % C on the first line, ((A % C) + (B % C)) % C on the second line, (A × B) % C on the third line, and ((A % C) × (B % C)) % C on the fourth line.

Examples3

  1. Example 1

    Input
    5 8 4
    
    Expected output
    1
    1
    0
    0
    
  2. Example 2

    Input
    2 3 5
    
    Expected output
    0
    0
    1
    1
    
  3. Example 3

    Input
    10 20 7
    
    Expected output
    2
    2
    4
    4