In this exercise, we say that a natural number is round in base b, when the sum of of its digits in base b equals its number of digits in this base.
For example, the number 34 is not round in base 10 (3 + 4 ≠ 2), but it is round in base 3, as
1· 33 + 0· 32 + 2 · 31 + 1 · 30 = 34 and 1 + 0 + 2 + 1 = 4. |
As another example, 511 is not round in base 16 as
1 · 162 + 15 · 161 + 15 · 160 = 511 and 1 + 15 + 15 = 31 ≠ 3, |
but it is round in base 2 (it has 9 ones, that add up to 9). Another example: 370273 is not round in base 2, neither in base 3, …, however it is round in base 608, because
1 · 6082 + 1 · 6081 + 1 · 6080 = 370273 and 1 + 1 + 1 = 3. |
A sequence of pairs of natural numbers (n,b), where n is a natural number and b≥ 2, is called bi-round if it does contain at least two pairs (n,b) with the property that n is round in base b.
Write a program that, given a sequence of pairs of natural numbers, determines whether it is bi-round or not.
Your program must include, use and implement the function
that indicates if a natural number is round on base b or not.
Input
The input is a non-empty sequence of pairs of natural numbers (x,b) with b≥ 2.
Output The program has to write if the input sequence is bi-round or not.
Please follow the format described in the examples. Your code should follow the style rules and include the appropriate comments.
Input
34 10 34 3 511 16 511 2 370273 2 370273 608
Output
Yes
Input
34 10
Output
No
Input
34 3
Output
No
Input
34 10 511 6 300 10 320 10 34 3
Output
Yes