<jupyter_start><jupyter_text>I saw a supposed "math trick" for calculating nth-roots. The premise is that $\sqrt[n]{x}$ is equal to the [digit sum](https://en.wikipedia.org/wiki/Digit_sum) of $x$, subtracted by $n$.---For example:$\sqrt[3]{343}$Digit Sum of 343: $3+4+3 = 10$Subtract n: $10 - 3 = 7$$\therefore \sqrt[3]{343} = 7$---This pattern is easily disproven:$\sqrt[2]{16}$Digit sum of 16: $1+6 = 7$Subtract n: $7-2 = 5$$\therefore \sqrt[2]{16} = 5???$---The cases where it does work are interesting, and I've written code in Python to explore the situations where the pattern works.---The two terms that you may want to modify are these: ```max_exponent = 20max_base = 1000````max_exponent` is the highest n-th root to check.`max_base` is the highest value for $x$ in $x^n$ to be checked. For example, a max exponent of 5 and max base of 10 would check as high as $\sqrt[5]{10^5}$---![](https://drive.google.com/uc?export=view&id=1qAfcAOw2cQPnddEnZMRQMu6O89Jrqfwt) A basic overview of Google Colaboratory can be found here:[Overview of Colaboratory Features](https://colab.research.google.com/notebooks/basic_features_overview.ipynb)Click on the `[ ]` or "Play icon"  below to load the two functions I've written.The first calculates a digit sum using recursion.The second is to make exponentiation a bit more explict for someone unfamiliar with Python(`a**b` is $a^b$)<jupyter_code>def digital_sum(x):
    if x < 10:
        return x
    return x % 10 + digital_sum(x // 10)  
    # "%" means modulo, which takes the remainder. 
    # "//" is division, discarding the remainder.

def power(base, exponent):
    return base ** exponent<jupyter_output><empty_output><jupyter_text>An English explanation of the following algorithm might be:The maximum exponent to test is 20.The maximum answer we're looking for is $1000^n$ Step 1: Start with an exponent of 1 and do everything after this step...Once complete, increase exponent by one and repeat, if exponent reaches 21 (20+1) then stop. We use `max_exponent + 1` because otherwise it would stop before calculating for 20. Step 2: Start with an base of 1 and do everything after this step...Once complete, increase base by one and repeat, if exponent reaches 1001 then stop, and go back to Step 1. Step 3:Calculate the digit sum of $x^n$, subtract $n$ and see if it's equal to $n$. If it is, proceed to Step 4, otherwise go back to Step 2. Step 4:Display the results of the calculation. When finished, go back to step 2.---Click on the `[ ]` or "Play icon"  below to see it run yourself!<jupyter_code>max_exponent = 20
max_base = 1000
for exponent in range(1, max_exponent + 1):
    # the two values are the start and stop number, but normally the stop isn't
    # included, so I add 1.
    for base in range(1, max_base + 1):
        if digital_sum(power(base, exponent)) - exponent == base:
            print(f"{base} ^ {exponent} = {power(base,exponent)}")
            print(f"Add the digits in {power(base,exponent)} to " +
                  f"get {digital_sum(power(base,exponent))} and then subtract {exponent}")
            print()<jupyter_output>2 ^ 2 = 4
Add the digits in 4 to get 4 and then subtract 2

5 ^ 2 = 25
Add the digits in 25 to get 7 and then subtract 2

8 ^ 2 = 64
Add the digits in 64 to get 10 and then subtract 2

14 ^ 2 = 196
Add the digits in 196 to get 16 and then subtract 2

17 ^ 2 = 289
Add the digits in 289 to get 19 and then subtract 2

5 ^ 3 = 125
Add the digits in 125 to get 8 and then subtract 3

6 ^ 3 = 216
Add the digits in 216 to get 9 and then subtract 3

7 ^ 3 = 343
Add the digits in 343 to get 10 and then subtract 3

14 ^ 3 = 2744
Add the digits in 2744 to get 17 and then subtract 3

15 ^ 3 = 3375
Add the digits in 3375 to get 18 and then subtract 3

16 ^ 3 = 4096
Add the digits in 4096 to get 19 and then subtract 3

39 ^ 6 = 3518743761
Add the digits in 3518743761 to get 45 and then subtract 6

62 ^ 9 = 13537086546263552
Add the digits in 13537086546263552 to get 71 and then subtract 9

63 ^ 9 = 15633814156853823
Add the digits in 15633814156853823 to get 72 and then subtract 9

78 ^ 12 = 50714860[...]
{'fraction_non_alphanumeric': 0.09307411907654921, 'fraction_numerical': 0.0818955042527339, 'mean_word_length': 3.6666666666666665, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 8, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '248551', 'license': 'MIT', 'n_tokens_mistral': 1579, 'n_tokens_neox': 1263, 'n_words': 614, 'path': 'mathtrick.ipynb', 'repo_name': 'WilliamRoyNelson/colaboratory-notebooks', 'size': '4115'}