[Community Puzzle] Number derivation

https://www.codingame.com/training/easy/number-derivation

Send your feedback or ask for help here!

Created by @nicola,validated by @ViktorCs,@Scarlatine and @Vestiaz.
If you have any issues, feel free to ping them.

I don’t understand, what exactly I should do. Even by looking at the test cases, I still have no clue. Is every integer n either a prime or a product of primes?

Yes, every positive integer is a product of primes: https://en.wikipedia.org/wiki/Integer_factorization

An example of how you can solve Testcase 4:
n = 42
42 = 2 * 21
42’ = (2 * 21)’ = 2’ * 21 + 2 * 21’ = 21 + 2 * 21’
21’ = (7*3)’ = 7’ * 3 + 3’ * 7 = 1 * 3 + 1 * 7 = 10
=> 42’ = 21 + 2 * 10 = 41

1 Like

Yes, except 1 and 0.
It’s the fundamental theorem of arithmetic.

I changed “given number” for “given positive integer” to make it clearer - though you can guess it easily from the “arithmetics” tag and it’s stated later than the number is >1.

Does this work for numbers with four prime numbers as for eg:210 goes on

Of course.

Great puzzle. Code implementation turned out to be quite short, but this shook some rust off my math knowledge.

1 Like