Base numbers

3.7

25 votes
Algorithms, Binary Search, Easy, Searching
Problem

You are given three integers a, b, and n. Your task is to determine the number of positive integers x[1,109] such that axx is an n-digit number of base b.

Input format

The input contains many test cases. Each test case is represented in a new line. Every line contains three integers, a, n, and b (1a,n109,2b10)

Note: There are at most 1000 test cases.

Output format

For each test case, print the answer.

 

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The input contains 2 testcases.

x=3 meets the first condition

x=1 and 2 meet the second one.

Editor Image

?