Given array of N elements. Find number of coprime pairs.

1 <= N <= 30000

1 <= A[i] <= 10^8

TL: 0.6s

ML: 64MB

# | User | Rating |
---|---|---|

1 | tourist | 3539 |

2 | V--o_o--V | 3338 |

3 | Um_nik | 3307 |

4 | Petr | 3297 |

5 | ecnerwala | 3282 |

6 | LHiC | 3266 |

7 | wxhtxdy | 3264 |

8 | Radewoosh | 3257 |

9 | Vn_nV | 3182 |

10 | dotorya | 3178 |

# | User | Contrib. |
---|---|---|

1 | Radewoosh | 207 |

2 | Errichto | 177 |

3 | neal | 159 |

4 | Ashishgup | 158 |

5 | PikMike | 157 |

6 | majk | 156 |

6 | Petr | 156 |

8 | rng_58 | 155 |

9 | Um_nik | 154 |

10 | 300iq | 153 |

Given array of N elements. Find number of coprime pairs.

1 <= N <= 30000

1 <= A[i] <= 10^8

TL: 0.6s

ML: 64MB

↑

↓

Codeforces (c) Copyright 2010-2018 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Jan/24/2019 06:38:53 (d1).

Desktop version, switch to mobile version.

Supported by

User lists

Name |
---|

Hmmm, I don't really know. But, I'll let you know as soon as I come up with a solution! (If I come up with one) :D

Preprocess all the primes smaller than 10

^{8}by Eratosthenes Sieve.Now, for all the numbers

a_{i}, make a vector of it's prime divisors (not counting the multiplicity). We will actually find the numbers of non-coprime pairs of numbers and subtract it fromn* (n- 1) / 2Suppose that, for some

i, we havea_{i}=p_{1}*p_{2}* ... *p_{k}. (We, again, disregard multiplicity). Note that the time allows us to go through all subsets of {p_{1},p_{2}, ...,p_{k}} for alli. Build two maps, cnt[] and sgn[]. cnt[X] tells us how many times subset with product equal to X appears in all elements of array a[], while sgn[X] tells us how many elements the subset has.And for the finale just use the Inclusion — Exclusion Principle.

I'm the author of this task :) It appeared on the national programming competition in Serbia this year.

Problem 6 (In Serbian)

The intended solution for 100 points is what The_Wolfpack has written, with a small correction — you only need to process primes up to 10

^{4}.Hvala obojici :)

Can I get the aforementioned problem in English? I really liked that concept. Thank You very much.

It's identical to the problem posted in the blog: Find the number of pairs

i,j(1 ≤i<j≤n) such thatgcd(a_{i},a_{j}) = 1. Constraints are: 1 ≤N≤ 30000, 1 ≤a_{i}≤ 10^{8}. TL = 0.6s. Problem statements are traditionally long and full of unnecessary details and stories.