Integers in Rational Bases
Time limit1sMemory limit512 MB
Given coprime p and q, write a positive integer n in the unique base p/q expansion whose digits are all at most p-1, printing digits 0-9, A-Z, a-z.
- Level
Hard8 of 10
- Topics
- Number theory, Math, Greedy, Implementation
- Solved
- No attempts yet
Problem
Given relatively prime positive integers , any positive integer can be written uniquely as a linear combination of powers of with coefficients ranging from to .
For example,
Write a program that finds the base expansion of an integer . Use the characters 0-9, then A-Z, then a-z as digits for the base expansion.
Input
Input consists of a single line containing 3 space-separated decimal values. They are the numerator () of the fractional base, followed by the denominator () of the fractional base, followed by the positive integer to be represented in base . The values of , , and are chosen so that and are relatively prime, the expansion has at most 40 digits, and fits in a 32-bit unsigned integer.
Output
Your program should produce a single output line containing a string of digits [0-9,A-Z,a-z] with the most significant digit first.