# Learn Python and Algorithm Using TopCoder - 6(InterestingDigits)

Today, we will use the math! math…

Problem Statement

The digits 3 and 9 share an interesting property. If you take any multiple of 3 and sum its digits, you get another multiple of 3. For example, 118*3 = 354 and 3+5+4 = 12, which is a multiple of 3. Similarly, if you take any multiple of 9 and sum its digits, you get another multiple of 9. For example, 75*9 = 675 and 6+7+5 = 18, which is a multiple of 9. Call any digit for which this property holdsinteresting, except for 0 and 1, for which the property holds trivially.

A digit that is interesting in one base is not necessarily interesting in another base. For example, 3 is interesting in base 10 but uninteresting in base 5. Given anbase, your task is to return all the interesting digits for that base in increasing order. To determine whether a particular digit is interesting or not, you need not considerallmultiples of the digit. You can be certain that, if the property holds for all multiples of the digit with fewer than four digits, then it also holds for multiples with more digits. For example, in base 10, you would not need to consider any multiples greater than 999.

The given base is n.

a*n²+b*n+c

a*n²-a+b*n-b+a+b+c (∵you should check a+b+c(sum of the digits))

a*(n²-1)+b*(n-1)+a+b+c

a*(n-1)*(n+1)+b*(n-1)+a+b+c

(n-1){a*(n+1)+b}+a+b+c **⋯ (1)**

If a+b+c is a multiple of the (n-1), **(1) **is a multiple of the (n-1).

∴we should find divisor of the (n-1)

**Code**

Next practice problem is ThePalindrome. 👋