Basic Modulo
Time limit1sMemory limit128 MB
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 and written in base . Write a program that computes the remainder of divided by and prints it in base .
Here, the remainder of divided by is the smallest non-negative integer such that for some integer .
Input
The input consists of several test cases. Each test case is given on a single line as three integers , , and , separated by spaces.
- is the base, with .
- and are base- integers whose digits are all between and .
- has at most digits and has at most digits.
The last line contains a single , which marks the end of the input.
Output
For each test case, print the remainder of divided by in base on its own line.