2 test cases wrong
use totient function otherwise you wont understand it.
watch this
sir the difference between yours and mine was only that u were storing all the outputs in an array or was there any another difference too your code https://ide.codingblocks.com/s/80398 mine code https://ide.codingblocks.com/s/80342