PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#BS0000194. Tìm các cơ số hợp lệ (Base n)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tìm các cơ số hợp lệ (Base n)
Base n
Source: AtCoder
Version: Phuoc Hung OJ Extended
Problem Statement
Given a decimal digit string of length 1 to 60 with no leading zero and an integer , let be the maximum digit of .
For each integer base , interpret as a representation in base . Its value is
Count the distinct integer values not exceeding . If contains only one digit, every valid base gives the same value, so the answer is either 0 or 1.
Input
- First line: the digit string .
- Second line: the integer .
Output
- Print the number of distinct representable integers not exceeding .
Subtasks
- Subtask 1 (20 points): ; has no leading zero; .
- Subtask 2 (30 points): ; has no leading zero; .
- Subtask 3 (50 points): ; has no leading zero; .
Examples
Input
22
10
Output
2
Explanation
For and , the largest digit is , so the smallest base is .
| Base | Value of 22 |
Valid? |
|---|---|---|
| 3 | Yes | |
| 4 | Yes | |
| 5 | No |
Every larger base also fails, so the answer is .