PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000203. Số chữ số 0 cuối và số chữ số của giai thừa (How many zeroes and how many digits?)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Số chữ số 0 cuối và số chữ số của giai thừa (How many zeroes and how many digits?)

Số chữ số 0 cuối và số chữ số của giai thừa (How many zeroes and how many digits?)

Source: UVa

Version: Phuoc Hung OJ Extended

Problem Statement

Given NN and base B≥2B\ge2, write the integer N!N! in base BB. Determine (1) its number of trailing zero digits and (2) its total number of digits. By definition 0!=10!=1, which has one digit and no trailing zero.

Input

One line with two integers N,BN,B.

Output

Print the trailing-zero count and the total digit count separated by one space.

Subtasks

  • Subtask 1 (20 points): 0≤N≤2000\le N\le 200; 2≤B≤8002\le B\le800.

  • Subtask 2 (30 points): 0≤N≤100000\le N\le 10000; 2≤B≤8002\le B\le800.

  • Subtask 3 (50 points): 0≤N≤10485750\le N\le 1048575; 2≤B≤8002\le B\le800.

Examples

Example 1

Input

2 10

Output

0 1

Explanation

2!=2 has one decimal digit and no trailing zeros.

Example 2

Input

5 16

Output

0 2

Explanation

5!=120=78 in hexadecimal, which has two digits and no trailing zeros.

Example 3

Input

5 10

Output

1 3

Explanation

5!=120 has one trailing zero and three decimal digits.