Code not passing test case

This is my code - https://ide.codingblocks.com/s/577726

This is correct but it shows run error when i submit the code and here array size is 10e+5, but when i decrease the array size to 1e4+5 then it runs but shows wrong ans.

Can you please tell me the reason for this?

Your code has lots of templates, tell me the approach you are using so that i can let you know if it’s correct or not. Also it’s not running for 1e4+5 value.

So i am using brute force here,
so i am just traversing from 1 to 100005 and then suppose if sum of factors of a number n is 12, then arr[12] = n.
So then i am just printing arr[s] is arr[s]!=0 and if it is 0 then printing -1.

and for calculating sum of factors i am using this formula sum *= ((p^k)+1 - 1) / (p-1) .
where p our the prime factors and k their powers

Instead do what , Find all the primes till 10^5 using seive. Now find sum of factors of numbers using prime numbers and (Mathematical formula sum of factors) Now for every test case simply check if it exist in array or not.
Reference code:

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.