# 2004 AIME II Problems/Problem 10

## Problem

Let $S$ be the set of integers between $1$ and $2^{40}$ whose binary expansions have exactly two $1$'s. If a number is chosen at random from $S,$ the probability that it is divisible by $9$ is $p/q,$ where $p$ and $q$ are relatively prime positive integers. Find $p+q.$

## Solution 1

A positive integer $n$ has exactly two 1s in its binary representation exactly when $n = 2^j + 2^k$ for $j \neq k$ nonnegative integers. Thus, the set $S$ is equal to the set $\{n \in \mathbb{Z} \mid n = 2^j + 2^k \,\mathrm{ and }\, 0 \leq j < k \leq 39\}$. (The second condition ensures simultaneously that $j \neq k$ and that each such number less than $2^{40}$ is counted exactly once.) This means there are ${40 \choose 2} = 780$ total such numbers.

Now, consider the powers of $2$ mod $9$: $2^{6n} \equiv 1, 2^{6n + 1} \equiv 2, 2^{6n + 2} \equiv 4, 2^{6n + 3} \equiv 8 \equiv -1,$ $2^{6n + 4} \equiv 7 \equiv -2,$ $2^{6n + 5} \equiv 5 \equiv -4 \pmod 9$.

It's clear what the pairs $j, k$ can look like. If one is of the form $6n$ (7 choices), the other must be of the form $6n + 3$ (7 choices). If one is of the form $6n + 1$ (7 choices) the other must be of the form $6n + 4$ (6 choices). And if one is of the form $6n + 2$ (7 choices), the other must be of the form $6n + 5$ (6 choices). This means that there are $7\cdot 7 + 7\cdot 6 + 7\cdot 6 = 49 + 42 +42 = 133$ total "good" numbers.

The probability is $\frac{133}{780}$, and the answer is $133 + 780 = \boxed{913}$.

## Solution 2

Note that $2^3 \equiv -1\text{ (mod 9)}$. Since $2^6 = 64 \equiv 1\text{ (mod 9)}$, multiplying by $2^6$ gives $2^{3+6n} \equiv -1\text{ (mod 9)}$.

The solutions that work are in the form $2^a+2^b$. Since $2^{3+6n}+1 \equiv 0\text{ (mod 9)}$, all of the solutions are in this form or this form multiplied by $2^x$ where $0 \leq 3+6n+x \leq 39$.

Now we just do casework: $$2^3+1: 2^0 \text{ to } 2^{36}$$ $$2^9+1: 2^0 \text{ to } 2^{30}$$ $$2^{15}+1: 2^0 \text{ to } 2^{24}$$ $$2^{21}+1: 2^0 \text{ to } 2^{18}$$ $$2^{27}+1: 2^0 \text{ to } 2^{12}$$ $$2^{33}+1: 2^0 \text{ to } 2^6$$ $$2^{39}+1: 2^0$$

So, the numerator is $37+31+25+19+13+7+1 = 133$. The denominator is just ${40 \choose 2}$, so the probability is $\frac{133}{780}$, and the answer is $133 + 780 = \boxed{913}$.

 2004 AIME II (Problems • Answer Key • Resources) Preceded byProblem 9 Followed byProblem 11 1 • 2 • 3 • 4 • 5 • 6 • 7 • 8 • 9 • 10 • 11 • 12 • 13 • 14 • 15 All AIME Problems and Solutions