Codeforces 1189E. Count Pairs Codeforces Round #572 (Div. 2)


Problem link

Let's transform condition a little bit. aiaj0 mod , so the condition is equivalent: That's why we just need to count the number of pairs of equal numbers in the array 

⇔(ai−aj)(ai+aj)(a2i+a2j)≡(ai−aj)k   //Both side multiple (ai−aj)
⇔a4i−a4j≡kai−kaj

⇔a4i−kai≡a4j−kaj
bi=(ai4kai) p. It's easy to do it, for example, using map. Complexity O(n) or O(nlog(n)).

A solution in c++


Post a Comment

0 Comments