Page 1 of 1

BdMO Regional 2021 Secondary P7

Posted: Mon Mar 29, 2021 11:51 pm
by Pro_GRMR
How many four-digit numbers $\overline{abba}$ are there such that $\overline{abba}$ is divisible by $\overline{aa}$?
Or,
Mursalin takes a four-digit palindromic number $n$ and deletes its middle two digits to obtain a two-digit number $m$. If $\frac{n}{m}$ is an integer, how many possible choices for $n$ are there?

Re: BdMO Regional 2021 Secondary P7

Posted: Tue Mar 30, 2021 12:36 am
by Pro_GRMR
Pro_GRMR wrote:
Mon Mar 29, 2021 11:51 pm
How many four-digit numbers $\overline{abba}$ are there such that $\overline{abba}$ is divisible by $\overline{aa}$?
Or,
Mursalin takes a four-digit palindromic number $n$ and deletes its middle two digits to obtain a two-digit number $m$. If $\frac{n}{m}$ is an integer, how many possible choices for $n$ are there?
If we assume $a$ can be equal to $b$ in the first variant then both are actually the same question. Now let's solve them.
  • We are given that:
    $\overline{aa}$ $\vert$ $\overline{abba}$
    $\Longleftrightarrow$ $a$ $\vert$ $\overline{abba}$ and $11$ $\vert$ $\overline{abba}$
    $\Longleftrightarrow$ $a$ $\vert$ $\overline{abba}$
    $\Longleftrightarrow$ $a$ $\vert$ $\overline{bb0}$
    $\Longleftrightarrow$ $a$ $\vert$ $b*2*5*11$
Since $a$ is a digit $a\in\{0,1,2,3,4,5,6,7,8,9\}$

We can do a case by case check:
$a \not= 0$
If $a = 1$ , $b\in\{0,1,2,3,4,5,6,7,8,9\}$
If $a = 2$ , $b\in\{0,1,2,3,4,5,6,7,8,9\}$
If $a = 3$ , $b\in\{0,3,6,9\}$
If $a = 4$ , $b\in\{0,2,4,6,8\}$
If $a = 5$ , $b\in\{0,1,2,3,4,5,6,7,8,9\}$
If $a = 6$ , $b\in\{0,3,6,9\}$
If $a = 7$ , $b\in\{0,7\}$
If $a = 8$ , $b\in\{0,4,8\}$
If $a = 9$ , $b\in\{0,9\}$
Adding them all up we get $\boxed{50}$ such palindromes

Here is a computational approach in C++:

Code: Select all

#include <bits/stdc++.h>
using namespace std;

bool ispalindrome(int i)
{
    string str = to_string(i);
    string rstr = str;
    reverse(rstr.begin(), rstr.end());

    if (rstr == str)
        return true;
    else
        return false;
}

int main(void)
{
    int count = 0, m;
    for (int n = 1000; n <= 9999; n++)
    {
        if (ispalindrome(n)) // Checks if a number is palindrome
        {
            m = (n / 1000) * 11; // Makes a two-digit palindrome m out of the first digit of n
            if (n % m == 0)
            {
                count++; // If m divides n add 1 to the tally
            }
        }
    }
    cout << count << endl;
}