Consider all integer combinations of for and :
If they are then placed in numerical order, with any repeats removed, we get the following sequence of 15 distinct terms:
How many distinct terms are in the sequence generated by for and ?
The tricky part of this problem was getting JavaScript to handle 𝔹𝕀𝔾®
numbers. Thankfully the BigInt is here and it made things a lot easier. I made
two helper functions: one to put my numbers in an array and another to trim extra
numbers after the fact.
I run two nested for loops and compute every power, inserting the values as
I go.
A major breakthrough on bringing the speed down for this problem was using a
binary search for inserting the numbers into the array. Another was trimming
the array of extra numbers instead of searching for duplicates before inserting.
Using a binary search before the fact only cost me about 1ms though.
103,541