Codeforces и Polygon могут быть недоступны в период с 23 мая, 7:00 (МСК) по 23 мая, 11:00 (МСК) в связи с проведением технических работ. ×

Блог пользователя Evan_Shareef

Автор Evan_Shareef, история, 19 месяцев назад, По-английски

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.

  • Проголосовать: нравится
  • -1
  • Проголосовать: не нравится

»
19 месяцев назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

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

  • »
    »
    19 месяцев назад, # ^ |
      Проголосовать: нравится 0 Проголосовать: не нравится

    Can you please elaborate a little bit?

    • »
      »
      »
      19 месяцев назад, # ^ |
        Проголосовать: нравится 0 Проголосовать: не нравится

      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}$$$