Module: Number systems


Problem

5 /9


Easy calculation

Problem

Natural number n is given. It is necessary to convert it to k-ary number system and find the difference between the product and the sum of its digits in this number system.
 
For example, let's say \(n = 239\), \(k = 8\). Then the representation of the number n in the octal system — \(357\) and the answer to the problem is \(3 \cdot 5 \cdot 7 ? (3 + 5 + 7) = 90\).
 
 
Input
String contains two natural numbers: n and k (\(1 <= n <= 10^9 \), \(2 <= k <= 10\)). Both of these numbers are given in decimal notation.
 
Output
Print the answer to the problem (in decimal notation).
 

 

Examples
# Input Output
1 239 8 90
2 1000000000 7 -34