The formula
Take for instance the number 300
- The prime factors of 300 are
[2, 3, 5]
(unique numbers that are factors of 300 and prime) - Squaring each of those numbers will give
you
[4, 9, 25]
- Summing that list will give you
4 + 9 + 25 = 38
- Finally subtract that sum (38) from your original number
300-38 = 262
(this is the result)
Input
Your input will be a positive integer greater than 2. You must check all numbers from 2 to the input value (inclusive) and find the number that produces the greatest result with the formula above.
Output
Your output will be two numbers separated by a space, comma, newline or whatever you language allows (the separation is necessary to distinguish the two numbers). These can be output to a file, stdout, or whatever your language uses. Your goal is to find the number in the range that produces the maximum output when run through the formula above. The first number displayed should be the starting number (like 300) and the second number should be the output that the formula produced (like 262)
Test Cases
Input: 3 Output: 2, -2
Input: 10 Output: 8, 4
Input: 50 Output: 48, 35
Input: 1000 Output: 1000, 971
Input: 9999 Output: 9984, 9802
Worked Through Example
Consider the input of 10, we must run the formula for all numbers from 2-10 (inclusive)
Num PrimeFacs PrimeFacs^2 SumPrimeFacs^2 Result
2 [2] [4] 4 -2
3 [3] [9] 9 -6
4 [2] [4] 4 0
5 [5] [25] 25 -20
6 [2, 3] [4, 9] 13 -7
7 [7] [49] 49 -42
8 [2] [4] 4 4
9 [3] [9] 9 0
10 [2, 5] [4, 25] 29 -19
As you can see the greatest result is 4
, which was a result of inputting the value 8
into the formula. That means the output for an input of 10
should be 8, 4
Scoring & Rules
The default rules for inputs and outputs apply: Default for Code Golf: Input/Output methods
The standard loopholes are forbidden: Loopholes that are forbidden by default
Submissions can be functions or full programs
Shortest code in bytes wins
50
:35, 48
? \$\endgroup\$