My teacher taught me a shortcut for finding number of rational terms in $\left(a^{\frac{1}{p}}+b^{\frac{1}{q}}\right)^n$.
For example, find the number of rational terms in $\left(5^{\frac{1}{6}}+2^{\frac{1}{8}}\right)^{100}$.
Algorithm:
- Find LCM of $(p,q)$. In the above example, its $24$.
- Divide $n$ by the LCM obtained. Let quotient be $Q$ and remainder be $R$.
- If $R=0$, number of rational terms is $Q+1$. Else its $Q$.
In the above example, $R\neq 0$. So number of rational terms is $4$.
How did he derive this shortcut?
Since the binomial expansion of this expression is $$ \left(a^{1/p} + b^{1/q}\right)^n=\sum_{i=0}^{n}{{n}\choose{i}}a^{i/p}b^{(n-i)/q}, $$ the $i$-th term is certainly rational (indeed, an integer) when $i\equiv 0$ (mod $p$) and $i\equiv n$ (mod $q$). By the Chinese remainder theorem, all solutions to these two equations are equal modulo ${\text{lcm}}(p, q)$; i.e., we get one solution every ${\text{lcm}}(p, q)$ steps. Therefore we get $Q$ or $Q+1$ solutions (in the notation of the problem) if the LCM doesn't divide $n$, and $Q+1$ solutions if the LCM divides $n$ (in which case $q$ divides $n$ as well, so the solutions start at $i=0$). When the LCM doesn't divide $n$, you need to find the first solution to decide if the result will be $Q$ or $Q+1$. This is the cause of "exceptions" like $\left(2 + 3^{1/4}\right)^6$.
The count, moreover, depends on there not being any other rational terms. I think this is guaranteed only if $a$ and $b$ are squarefree and coprime.