oj mrJudge
Toggle navigation
  • Login
    • Forget Password
      Login
User Image

Hello, Stranger

Guest
  • Analysis Mode
  • Problems
    • All Problems
    • Latest Problems
  • Join Us Now
  • Registration
  • Contact Us
  • Infomation
  • About
    • Terms of Use
    • Technical Specifications
    • Credits

xorb Batch , stdin/stdout

Registered Users Only

Please login to utilize this feature.

Do note that this website only supports submissions in C++.

xorb.html

Problem Description

Gug was learning about the XOR operator today, and has decided to define his own operation, the xorb operation, which stands for XORing in base B!

The procedure for XORing in base B is defined as follows:

  1. First, convert X and Y into base B.
  2. For each digit position, let the digit in X be m and the digit in Y be n. The digit in that position in the answer will be (m+n) modulo B.
  3. Convert the answer back to the original base.

Refer to the samples for more details.

Given three integers, X, Y and B, your task is to implement this xorb operation and find the answer.

Limits

Subtask 1 (33%): 1 ≤ X, Y ≤ 109, B = 2.

Subtask 2 (67%): 1 ≤ X, Y, B ≤ 109.

Subtask 3 (0%): Sample Testcases.

Input

The only line of input will contain three integers, X, Y and B.

Output

The only line of output should contain one integer, the answer of the xorb operation.

Sample Testcase 1

Input

5 3 2

Output

6

Explanation

When converted to base 2, X = "101" and Y = "011". Therefore, by comparing each digit:

  • first digit: (1 + 0) % 2 = 1.
  • second digit: (0 + 1) % 2 = 1.
  • third digit: (1 + 1) % 2 = 0.

Therefore the final answer is "110", which converts back to 6.

Sample Testcase 2

Input

170 131 5

Output

276

Tags

Math

Subtasks and Limits

Subtask Score #TC Time Memory Scoring
133211s256MBMinimum
267421s256MBMinimum
3021s256MBMinimum

Judge Compile Command

g++-8 ans.cpp -o xorb -Wall -Wshadow -static -O2 -lm -m64 -s -w -std=gnu++17 -fmax-errors=512

Accepted Submissions

subIDUserTimeMax Time

Past Submissions

subIDUserTimeScore
mrJudge 09.05.20
Copyright © 2020 mrJudge. All rights reserved.