This question is marked "community wiki".
asked 06 Jun '15, 11:19

The question has been closed for the following reason "Duplicate Question" by rcsldav2017 18 Aug '15, 00:03
I guess your 'ct' array stands for number of divisors and you are counting all divisors so that you can answer each query as (total divisors/2) ^ N which takes O(log(n)) time per query and O(n*log(n)) preprocessing. Instead of increasing 'ct' by 1 everywhere, you can instead multiply it by i. Obviously this means you initialize ct as 1 for all elements. Also now you don't have to care about square root stuff. Each query can be answered simply as ct[n] which is O(1) ! answered 06 Jun '15, 15:33
@sumeet_varma again TLE...
(06 Jun '15, 17:42)
@sumeet_varma ...what should be ans for N==1??
(06 Jun '15, 18:12)
