Project Euler 127 - abc-hits
Official link: https://projecteuler.net/problem=127
Note: Code took ~760 seconds to run but I'm happy with my solution
Thought Process
I brute forced this problem with a few important tricks
Note that gcd(c, a) = gcd(a + b, a) = gcd(a, b) therefore if gcd(a, b) = 1 this implies that gcd(a, c) = gcd(b, c) = 1. This means we only need to check if the gcd of one pair is 1 instead of all 3.
Since a, b, c are pairwise co-prime then rad(a), rad(b), rad(c) are also pairwise co-prime, therefore rad(abc) = rad(a) * rad(b) * rad(c)
Using a sieve (Very similar to the sieve of Eratosthenes) we can precompute the rad of all numbers up till N.
In our brute force search, we loop through possible a, and b and instead of first checking if gcd(a, b) = 1, we first check if rad(abc) > c as this operation by step (3) is instant. Then we check the gcd condition for a valid abc-hit
Interactive Code
Input an Integer (yourinput)
Code will output the sum of c where (a, b, c) is an abc-hit and c < yourinput