# Sherlock and Queries

# Sherlock and Queries

+ 1 comment Got my 30 points, but I thought the modulus part could have been clearer. Someone else suggested it here and got down-voted, but I'll suggest it again anyways: Making the sample case actually demonstrate the effects of the modulus would make it a much better sample.

+ 1 comment For each multiple say x, of 1 in 1 to N, we have to multiply A[x] with C[1] p1 times.

For each multiple say x, of 2 in 1 to N, we have to multiply A[x] with C[2] p1 times.

for clarity, should probably be:

For each multiple x of B[1] in x = 1 to N, multiply A[x] by C[1].

For each multiple y of B[2] in y = 1 to N, multiply A[x] by C[2].

+ 0 comments WOW such a nice question felt really good after solving it !!

+ 0 comments This was a good problem to solve - worked out my brain quite a bit :)

In the end though, like everyone pointed out, the final algorithm is quite simple if you understand what all the multiplication operations are doing. :-)

+ 2 comments I wrote a code whose complexity is approximately O(M*log(N)) in avarage case.(in best case O(M)). When integers of B arrays become small number such as 15-20, complexity approach O(N*M) which is worst case. What is the trick of this question? Make worst case and avarage case complexity linearithmic time or better?

Sort 61 Discussions, By:

Please Login in order to post a comment