Basic Modulo

Time limit1sMemory limit128 MB

Summary
Read base-b numbers p and m, with p up to 1000 digits, and print the remainder of p divided by m in base b.
Level

Medium4 of 10

Topics
Math, Number theory, Implementation, String
Solved
No attempts yet

Problem

You are given two non-negative integers pp and mm written in base bb. Write a program that computes the remainder of pp divided by mm and prints it in base bb.

Here, the remainder of pp divided by mm is the smallest non-negative integer kk such that p=a⋅m+kp = a \cdot m + k for some integer aa.

Input

The input consists of several test cases. Each test case is given on a single line as three integers bb, pp, and mm, separated by spaces.

  • bb is the base, with 2≤b≤102 \le b \le 10.
  • pp and mm are base-bb integers whose digits are all between 00 and b−1b-1.
  • pp has at most 10001000 digits and mm has at most 99 digits.

The last line contains a single 00, which marks the end of the input.

Output

For each test case, print the remainder of pp divided by mm in base bb on its own line.

Examples1

  1. Example 1

    Input
    2 1100 101
    10 123456789123456789123456789 1000
    0
    
    Expected output
    10
    789