Round numbers (2) X87201


Statement
 

pdf   zip

In this exercise, we say that a natural number is round in base bb, when the sum of of its digits in base bb equals its number of digits in this base.

For example, the number 34 is not round in base 1010 (3+423 + 4 \neq 2), but it is round in base 33, as 133+032+231+130=34 and 1+0+2+1=4.1\cdot 3^3 + 0\cdot 3^2 + 2 \cdot 3^1 + 1 \cdot 3^0 = 34 \text{ and } 1 + 0 + 2 + 1 = 4. As another example, 511511 is not round in base 1616 as 1162+15161+15160=511 and 1+15+15=313,1 \cdot 16^2 + 15 \cdot 16^1 + 15 \cdot 16^0 = 511 \text{ and } 1 + 15 + 15 = 31 \neq 3, but it is round in base 22 (it has 99 ones, that add up to 99). Another example: 370273370273 is not round in base 22, neither in base 33, …, however it is round in base 608608, because 16082+16081+16080=370273 and 1+1+1=3.1 \cdot 608^2 + 1 \cdot 608^1 + 1 \cdot 608^0 = 370273 \text{ and } 1 + 1 + 1 = 3.

A sequence of pairs of natural numbers (n,b)(n,b), where nn is a natural number and b2b\geq 2, is called bi-round if it does contain at least two pairs (n,b)(n,b) with the property that nn is round in base bb.

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

    bool round (int n, int b);

that indicates if a natural number is round on base bb or not.

Input

The input is a non-empty sequence of pairs of natural numbers (x,b)(x,b) with b2b\geq 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.

Public test cases
  • 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
    
  • Information
    Author
    Professorat de PRO1
    Language
    English
    Translator
    Maria Serna
    Original language
    Catalan
    Other languages
    Catalan Spanish
    Official solutions
    Unknown.
    User solutions
    C++ Python