https://www.codechef.com/LOCSEP17/problems/JMAGNUM/ I got TLE on cases >10^3. Please someone help me understand the solution. asked 03 Oct '17, 14:31

You can use a sieve and for each prime, instead of just using a flag to mark it as prime or not, you can store the sum of the prime divisors. After that you can take the prefix sum to answer each test case in O(1). answered 03 Oct '17, 14:37

3 precomputations will be needed.
well written code : CODE answered 03 Oct '17, 14:36
