Evan_Shareef's blog

By Evan_Shareef, history, 19 months ago, In English

Recently, I was trying to solve a problem. To solve that I shall have to solve a sub problem. The sub problem is:

I will be provided some values. I want to find number of pairs possible for that set of values who have gcd>1

Can anyone suggest an efficient approach? I just want you to give me hints so that I can start from that point of view and move forward.

  • Vote: I like it
  • -1
  • Vote: I do not like it

»
19 months ago, # |
  Vote: I like it 0 Vote: I do not like it

if the values are $$$\le 10^6$$$, you can try to check $$$d,2d,3d...$$$ for each $$$2\le d \le 10^6$$$

  • »
    »
    19 months ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Can you please elaborate a little bit?

    • »
      »
      »
      19 months ago, # ^ |
        Vote: I like it 0 Vote: I do not like it

      make the array $$$cnt$$$, where $$$cnt_d$$$ means the number of occurrences of value $$$d$$$ in the array.

      And when you check $$$d$$$ and $$$2d$$$, whose gcd is $$$2$$$, the number of pairs they make is $$$cnt_d*cnt_{2d}$$$