Let $k = 2^{1/3}$. If $p \geq 5$, then $k(p - 1) > p$. We know that $r > q > p$, so if $p \geq 5$, then $2(p - 1)(q - 1)(r - 1) > pqr > pqr - 1$. So we must have $p = 2, 3 or 4$.

Suppose $pqr - 1 = n(p - 1)(q - 1)(r - 1)$. We consider separately the cases $n = 1, n = 2$ and $n \geq 3$. If $n = 1$, then $p + q + r = pq + qr + rp$. But that is impossible, because $p, q, r$ are all greater than $1$ and so $p < pq$, $q < qr$ and $r < rp$.

Suppose $n = 2$. Then $pqr - 1$ is even, so all $p, q, r$ are odd. In particular, $p = 3$. So we have $4(q - 1)(r - 1) = 3qr - 1$, and hence $qr + 5 = 4q + 4r$. If $q \geq 9$, then $qr \geq 9r > 4r + 4q$. So we must have $q = 5$ or $7$. If $q = 5$, then we find $r = 15$, which gives a solution. If $q = 7$, then we find $r = 23/3$ which is not a solution.

The remaining case is $n \geq 3$. If $p = 2$, we have $n(qr - q - r + 1) = 2qr - 1$, or $(n - 2)qr + (n + 1) = nq + nr$. But $q \geq 3$, so $(n - 2)qr \geq (3n - 6)r \geq 2nr for n \geq 6$, so we must have $n = 3$, $4$ or $5$. If $n = 3$, then $qr + 4 = 3q + 3r$. If $q \geq 6$, then $qr \geq 6r > 3q + 3r$, so $q = 3$, $4$ or $5$. Checking we find only $q = 4$ gives a solution: $p = 2, q = 4, r = 8$. If $n = 4$, then $(n - 2)qr$, $nq$ and $nr$ are all even, but $(n + 1)$ is odd, so there is no solution. If $n = 5$, then $3qr + 6 = 5q + 5r$. $q = 3$ gives $r = 9/4$, which is not a solution. $q \geq 4$ gives $3qr > 10r > 5q + 5r$, so there are no solutions.

If $p = 3$, we have $2n(qr - q - r + 1) = 3qr - 1$, or $(2n - 3)qr + (2n + 1) = 2nq + 2nr$. But $q \geq 4$, so $(2n - 3)qr \geq (8n - 12)r \geq 4nr > 2nr + 2nq$. So there are no solutions. Similarly, if $p = 4$, we have $(3n - 4)qr + (3n + 1) = 3nq + 3nr$. But $q \geq 4$, so $(3n - 4)qr \geq (12n - 16)r > 6nr > 3nq + 3nr$, so there are no solutions.

(*
  Authors: Wenda Li
*)

theory imo_1992_p1 imports
  Complex_Main
  "HOL-Computational_Algebra.Computational_Algebra"
begin


theorem imo_1964_p2:
  fixes a b c :: real
  assumes "0 < a \<and> 0 < b \<and> 0 < c"
    and "c < a + b"
    and "b < a + c"
    and "a < b + c"
  shows "a^2 * (b + c - a) + b^2 * (c + a - b)
    + c^2 * (a + b - c) \<le> 3 * a * b * c"

Suppose $a, b, c$ are the sides of a triangle. Prove that

$a^2(b+c-a)+b^2(c+a-b)+c^2(a+b-c)\le{3abc}.$

We can use the substitution $a=x+y$, $b=x+z$, and $c=y+z$ to get

$2z(x+y)^2+2y(x+z)^2+2x(y+z)^2\leq 3(x+y)(x+z)(y+z)$

$2zx^2+2zy^2+2yx^2+2yz^2+2xy^2+2xz^2+12xyz\leq 3x^2y+3x^2z+3y^2x+3y^2z+3z^2x+3z^2y+6xyz$

$x^2y+x^2z+y^2x+y^2z+z^2x+z^2y\geq 6xyz$

$\frac{x^2y+x^2z+y^2x+y^2z+z^2x+z^2y}{6}\geq xyz=\sqrt[6]{x^2yx^2zy^2xy^2zz^2xz^2y}$

This is true by AM-GM. We can work backwards to get that the original inequality is true.

(*
  Authors: Wenda Li
*)

theory imo_1964_p2
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
  "HOL-Number_Theory.Number_Theory"
begin


theorem algebra_abpbcpcageq3_sumaonsqrtapbgeq3onsqrt2:
  fixes a b c :: real
  assumes "0 < a \<and> 0 < b \<and> 0 < c"
    and "3 \<le> a * b + b * c + c * a"
  shows "3 / sqrt 2 \<le> a / sqrt (a + b)
    + b / sqrt (b + c) + c / sqrt (c + a)"

For positive real numbers a, b, c, such that $3 \leq ab+bc+ca$, show that $3/\sqrt{2} \leq a/\sqrt{a+b} + b/\sqrt{b+c} + c/\sqrt{c+a}$.

From Holder's inequality, we have $(\sum \frac{a}{\sqrt{a+b}})^{2/3} (\sum a(a+b))^{1/3} \geq \sum a$.
Hence $\sum \frac{a}{\sqrt{a+b}} \geq \frac{(\sum a)^{3/2}}{(\sum a(a+b))^{1/2}}$. It thus suffices to prove $\frac{(\sum a)^3}{\sum a(a+b)} \geq \frac{9}{2}$, which is equivalent to $2(\sum a)^3 \geq 9 (\sum a^2 + \sum ab)$.

Let $p=\sum a$ and $q=\sum ab$. From the assumption we know that $q \geq 3$. The inequality becomes $2p^3\geq 9(p^2-q)$, which is equivalent to $2p^3+9q\geq 9p^2$. By the AM-GM inequality, we have $2p^3 + 9q\geq 2p^3 + 27 = p^3 + p^3 + 27 \geq 3*(p^3*p^3*27)^{1/3} = 9p^2$. Hence the inequality holds.

(*
  Authors: Wenda Li
*)

theory algebra_abpbcpcageq3_sumaonsqrtapbgeq3onsqrt2
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
begin


By multiplying the entire equation by $3-2=1$, all the terms will simplify by difference of squares, and the final answer is $\textbf{(C)} ~3^{128}-2^{128}$.

Additionally, we could also multiply the entire equation (we can let it be equal to $x$) by $2-3=-1$. The terms again simplify by difference of squares. This time, we get $-x=2^{128}-3^{128} \Rightarrow x=3^{128}-2^{128}$. Both solutions yield the same answer.

(*
  Authors: Wenda Li
*)

theory amc12a_2021_p9
  imports Complex_Main "HOL-Library.Code_Target_Numeral"
begin


theorem imo_1982_p1:
  fixes f :: "nat \<Rightarrow> nat"
  assumes "\<forall> m n. f (m + n) - f m - f n = 0 \<or> f (m + n) - f m - f n = 1"
    and "f 2 = 0"
    and "0 < f 3"
    and "f 9999 = 3333"
  shows "f 1982 = 660"

The function $f(n)$ is defined on the positive integers and takes non-negative integer values. $f(2)=0,f(3)>0,f(9999)=3333$ and for all $m,n:$$ f(m+n)-f(m)-f(n)=0 \text{ or } 1. $Determine $f(1982)$. Show that it is 660.

Clearly $f(1) \ge 1 \Rightarrow f(m+1) \ge f(m)+f(1) \ge f(m)+1$ so $f(9999) \ge 9999$.Contradiction!So $f(1)=0$.This forces $f(3)=1$.Hence $f(3k+3) \ge f(3k)+f(3)>f(3k)$ so the inequality $f(3)<f(6)<\cdots<f(9999)=3333$ forces $f(3k)=k \forall k \le 3333$.Now $f(3k+2) \ge k+1 \Rightarrow f(6k+4) \ge 2k+2 \Rightarrow f(12k+8) \ge 4k+4 \le f(12k+9)=4k+3$(Note:This is valid for $12k+9 \le 9999$ or $3k+2 \le 2499$).Contradiction!Hence the non-decreasing nature of $f$ gives $f(3k+1)=k$.Hence $f(n)=\lfloor\frac{n}{3}\rfloor \forall 1\le n \le 2499$.

So $f(1982)=\lfloor\frac{1982}{3}\rfloor=660$.

(*
  Authors: Wenda Li
*)

theory imo_1982_p1 imports
  Complex_Main
  "HOL-Computational_Algebra.Computational_Algebra"
begin


theorem mathd_algebra_362:
  fixes a b :: real
  assumes "a^2 * b^3 = 32 / 27"
    and "a / b^3 = 27 / 4"
  shows "a + b = 8 / 3"

If $a$ and $b$ are real numbers, $a^2b^3=\frac{32}{27}$, and $\frac{a}{b^3}=\frac{27}{4}$, what is $a+b$? Show that it is \frac83.

Rearranging the second equation, we have that $b^3=\frac{4}{27}a$. If we substitute this into the original equation, we get $\frac{4}{27}a^3=\frac{32}{27}$; after multiplying each side by $\frac{27}{4}$ and taking the cube root, we see that $a=2$. Substituting $a$ into the first equation, we get that $b^3=\frac{8}{27}$ or $b=\frac23$. Thus, $a+b=2+\frac23=\frac83$.

(*
  Authors: Wenda Li
*)

theory mathd_algebra_362
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
  "HOL-Number_Theory.Number_Theory"
begin


If $a,b,$ and $c$ are positive [[real number]]s such that $a(b+c) = 152, b(c+a) = 162,$ and $c(a+b) = 170$, then $abc$ is

$\mathrm{(A)}\ 672
\qquad\mathrm{(B)}\ 688
\qquad\mathrm{(C)}\ 704
\qquad\mathrm{(D)}\ 720
\qquad\mathrm{(E)}\ 750$ Show that it is 720.

Adding up the three equations gives $2(ab + bc + ca) = 152 + 162 + 170 = 484 \Longrightarrow ab + bc + ca = 242$. Subtracting each of the above equations from this yields, respectively, $bc = 90, ca = 80, ab = 72$. Taking their product, $ab \cdot bc \cdot ca = a^2b^2c^2 = 90 \cdot 80 \cdot 72 = 720^2 \Longrightarrow abc = 720 \Rightarrow \mathrm{(D)}$.

(*
  Authors: Wenda Li
*)

theory amc12b_2002_p19
  imports Complex_Main
begin


theorem mathd_algebra_289:
  fixes k t m n :: nat
  assumes "prime m \<and> prime n"
    and "t < k"
    and "k^2 + n - m * k  = 0"
    and "t^2 + n - m * t  = 0"
    and "0 < t"
  shows "m^n + n^m + k^t + t^k = 20"

The two positive integer solutions of the equation $x^2 - mx + n = 0$ are $k$ and $t$, where $m$ and $n$ are both prime numbers and $k > t$. What is the value of $m^n + n^m + k^t + t^k$? Show that it is 20.

From $x^2-mx+n=0$, we get $k+t=m$ and $kt=n$. Since $n$ is prime, one of $k$ and $t$ is $n$ and the other is 1. $k>t$, so $k=n$ and $t=1$. Then $m=n+1$. $m$ is also prime, so we have two consecutive integers that are prime. Since one of every two consecutive integers is even, and the only even prime is 2, we must have $n=2$ and $m=3$. Therefore, $m^n+n^m+k^t+t^k= 3^2+2^3+2^1+1^2=9+8+2+1=20$.

(*
  Authors: Wenda Li
*)

theory mathd_algebra_289
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
  "HOL-Number_Theory.Number_Theory"
begin


theorem numbertheory_3pow2pownm1mod2pownp3eq2pownp2:
  fixes n :: nat
  assumes "0 < n"
  shows "(3^(2^n) - 1) mod (2^(n + 3)) = (2::nat)^(n + 2)"

Show that for positive integer $n$, the remainder of $3^{2^n} - 1 \equiv 2^{n+2} \mod 2^{n+3}$.

We can prove this by induction on n. For the base case, $n=1$, when the result obviously holds.
For the inductive case, the hypothesis is $3^{2^n} - 1 \equiv 2^{n+2} \mod 2^{n+3}$, so we can obtain a natural number $p$ where $3^{2^n} - 1 = 2^{n+2} + p * 2^{n+3} = 2^{n+2}(1+2p)$.
Then we have $3^{2^{n+1}} = 3^{2^n*2} = (3^{2^n})^2 = (2^{n+2} * (1+2p) + 1)^2$.
Hence $3^{2^{n+1}} \equiv (2^{n+2} * (1+2p))^2 + 2 * 2^{n+2} * (1+2p) + 1 \equiv 2^{n+3}*(1+2p) + 1 \equiv 1\mod 2^{n+3}$.
Therefore $3^{2^{n+1}} -1 \equiv 0 \mod 2^{n+3}$. By induction, the statement holds true.

(*
  Authors: Wenda Li
*)

theory numbertheory_3pow2pownm1mod2pownp3eq2pownp2
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
  "HOL-Number_Theory.Number_Theory"
begin


theorem aime_1984_p7:
  fixes f :: "nat \<Rightarrow> nat"
  assumes h0: "\<forall> n\<ge>1000.  f n = n - 3"
      and h1: "\<forall> n < 1000. f n = f (f (n + 5))"
  shows "f 84 = 997"

The [[function]] f is defined on the [[set]] of [[integer]]s and satisfies $f(n)=\begin{cases}
n-3&\mbox{if}\ n\ge 1000\\
f(f(n+5))&\mbox{if}\ n<1000\end{cases}$

Find $f(84)$. Show that it is 997.

Define $f^{h} = f(f(\cdots f(f(x))\cdots))$, where the function $f$ is performed $h$ times. We find that $ f(84) = f(f(89)) = f^2(89) = f^3(94) = \ldots f^{y}(1004)$. $1004 = 84 + 5(y - 1) \Longrightarrow y = 185$. So we now need to reduce $f^{185}(1004)$.

Let’s write out a couple more iterations of this function:
$\begin{align*}f^{185}(1004)&=f^{184}(1001)=f^{183}(998)=f^{184}(1003)=f^{183}(1000)\\
&=f^{182}(997)=f^{183}(1002)=f^{182}(999)=f^{183}(1004)\end{align*}$
So this function reiterates with a period of 2 for $x$. It might be tempting at first to assume that $f(1004) = 1001$ is the answer; however, that is not true since the solution occurs slightly before that. Start at $f^3(1004)$:
$f^{3}(1004)=f^{2}(1001)=f(998)=f^{2}(1003)=f(1000)=997$

Note that we should also be suspicious if our answer is $1001$- it is a $4$-digit number, and we were not asked to, say, divide our number by $13$.

(*
  Authors: Wenda Li
*)

theory aime_1984_p7 imports Complex_Main
begin


theorem mathd_algebra_432:
  fixes x ::real
  shows "(x + 3) * (2 * x - 6) = 2 * x^2 - 18"

Expand $(x+3)(2x-6)$. Show that it is 2x^2-18.

Factoring a $2$ out of the second term gives $2(x+3)(x-3)=2(x^2-3^2)=2x^2-18$.

(*
  Authors: Wenda Li
*)

theory mathd_algebra_432
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
begin


theorem mathd_numbertheory_227:
  fixes x y n ::nat
  assumes "x / 4 + y / 6 = (x + y) / n"
    and "n\<noteq>0" "x\<noteq>0" "y\<noteq>0"
  shows "n = 5"

One morning each member of Angela's family drank an 8-ounce mixture of coffee with milk. The amounts of coffee and milk varied from cup to cup, but were never zero. Angela drank a quarter of the total amount of milk and a sixth of the total amount of coffee. How many people are in the family? Show that it is 5.

Suppose that the whole family drank $x$ cups of milk and $y$ cups of coffee. Let $n$ denote the number of people in the family. The information given implies that $\frac{x}{4}+\frac{y}{6}=\frac{x+y}{n}$. This leads to \[
3x(n-4)=2y(6-n).
\]Since $x$ and $y$ are positive, the only positive integer $n$ for which both sides have the same sign is $n=5$.

(*
  Authors: Wenda Li
*)

theory mathd_numbertheory_227 imports
  Complex_Main
  "HOL-Computational_Algebra.Computational_Algebra"
begin


theorem mathd_numbertheory_296:
  fixes n :: nat
  assumes "2 \<le> n"
    and "\<exists> x. x^3 = n"
    and "\<exists> t. t^4 = n"
  shows "4096 \<le> n"

What is the smallest positive integer, other than $1$, that is both a perfect cube and a perfect fourth power? Show that it is 4096.

If $n$ is a perfect cube, then all exponents in its prime factorization are divisible by $3$. If $n$ is a perfect fourth power, then all exponents in its prime factorization are divisible by $4$. The only way both of these statements can be true is for all the exponents to be divisible by $\mathop{\text{lcm}}[3,4]=12$, so such an $n$ must be a perfect twelfth power. Since we aren't using $1^{12}=1,$ the next smallest is $2^{12}=4096.$

(*
  Authors: Wenda Li
*)

theory mathd_numbertheory_296
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
  "HOL-Number_Theory.Number_Theory"
begin


theorem induction_prod1p1onk3le3m1onn:
  fixes n :: nat
  assumes "0 < n"
  shows "(\<Prod> k \<in> {1..<n+1}. (1 + 1 / k^3)) \<le> 3 - 1 / n"

Show that for any positive integer $n$, we have $\prod_{k=1}^n (1 + 1/k^3) \leq 3 - 1/n$.

We can prove this by induction on n. For the base case, $n=1$, the statement is trivial.
For the inductive case, we assume $\prod_{k=1}^{n_0} (1 + 1/k^3) \leq 3 - 1/n_0$.
Therefore, we have $\prod_{k=1}^{n_0+1} (1 + 1/k^3) \leq (3-1/n_0) (1 + 1/(n_0+1)^3) = 3 + \frac{3}{(n_0+1)^3}-\frac{1}{n_0}-\frac{1}{n_0 (n_0+1)^3}$.
It hence suffices to show that $\frac{3}{(n_0+1)^3}+\frac{1}{n_0+1} \leq \frac{1}{n_0} + \frac{1}{n_0 (n_0+1)^3}$, which is equivalent to
$3n_0 + n_0 (n_0+1)^2 \leq (n_0+1)^3 + 1$. Simplifying, we get
$n_0^2 - n_0 + 2 \geq 0$. This is obviously true for $n\geq 1$.

(*
  Authors: Wenda Li
*)

theory induction_prod1p1onk3le3m1onn
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
begin


theorem amc12a_2020_p10:
  fixes n ::nat
  assumes "n>0"
    and h0: "ln (ln n / ln 16) / ln 2
                = ln (ln n / ln 4) / ln 4"
  shows "n = 256"

There is a unique positive integer $n$ such that$\log_2{(\log_{16}{n})} = \log_4{(\log_4{n})}.$What is the sum of the digits of $n?$

$\textbf{(A) } 4 \qquad \textbf{(B) } 7 \qquad \textbf{(C) } 8 \qquad \textbf{(D) } 11 \qquad \textbf{(E) } 13$ Show that it is \textbf{(E) } 13.

Any logarithm in the form $\log_{a^b} c = \frac{1}{b} \log_a c.$ This can be proved easily by using change of base formula to base $a.$

So, the original equation $\log_2{(\log_{2^4}{n})} = \log_{2^2}{(\log_{2^2}{n})}$ becomes $\log_2\left({\frac{1}{4}\log_{2}{n}}\right) = \frac{1}{2}\log_2\left({\frac{1}{2}\log_2{n}}\right).$
Using log property of addition, we expand both sides and then simplify:
$\begin{align*}
\log_2{\frac{1}{4}}+\log_2{(\log_{2}{n}}) &= \frac{1}{2}\left[\log_2{\frac{1}{2}} +\log_{2}{(\log_2{n})}\right] \\
\log_2{\frac{1}{4}}+\log_2{(\log_{2}{n}}) &= \frac{1}{2}\left[-1 +\log_{2}{(\log_2{n})}\right] \\
-2+\log_2{(\log_{2}{n}}) &= -\frac{1}{2}+ \frac{1}{2}(\log_{2}{(\log_2{n})}).
\end{align*}$
Subtracting $\frac{1}{2}(\log_{2}{(\log_2{n})})$ from both sides and adding $2$ to both sides gives us $\frac{1}{2}(\log_{2}{(\log_2{n})}) = \frac{3}{2}.$
Multiplying by $2,$ exponentiating, and simplifying gives us
$\begin{align*}
\log_{2}{(\log_2{n})} &= 3 \\
\log_2{n}&=8 \\
n&=256.
\end{align*}$
Adding the digits together, we have $2+5+6=\textbf{(E) } 13.$

(*
  Authors: Wenda Li
*)

theory amc12a_2020_p10
  imports Complex_Main
begin


theorem mathd_algebra_314:
  fixes n :: nat
  assumes "n = 11"
  shows "(1 / 4)^(n + 1) * 2^(2 * n) = 1 / (4::real)"
  unfolding assms

If $n = 11$, then what is $\left(\frac{1}{4}\right)^{n+1} \cdot 2^{2n}$? Show that it is \frac{1}{4}.

By simplifying exponents, we have $2^{2n} = 4^n$.  So, our overall expression is $\frac{4^n}{4^{n+1}}$.  This simplifies to $\frac{1}{4}$.  Throughout the course of this calculation, we did not have to plug in the value of 11 for $n$, but the answer may be similarly obtained with this substitution.

(*
  Authors: Wenda Li
*)

theory mathd_algebra_314
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
  "HOL-Number_Theory.Number_Theory"
begin


theorem mathd_algebra_354:
  fixes a d :: real
  assumes "a + 6 * d = 30"
    and "a + 10 * d = 60"
  shows "a + 20 * d = 135"

In an arithmetic sequence, the 7th term is 30, and the 11th term is 60. What is the 21st term of this sequence? Show that it is 135.

Let $a$ be the first term in this arithmetic sequence, and let $d$ be the common difference.  Then the $7^{\text{th}}$ term is $a + 6d = 30$, and the $11^{\text{th}}$ term is $a + 10d = 60$.  Subtracting these equations, we get $4d = 30$, so $d = 30/4 = 15/2$.

Then the $21^{\text{st}}$ term is $a + 20d = (a + 10d) + 10d = 60 + 10 \cdot 15/2 = 135$.

(*
  Authors: Wenda Li
*)

theory mathd_algebra_354
  imports Complex_Main "HOL-Computational_Algebra.Computational_Algebra"
  "HOL-Number_Theory.Number_Theory"
begin