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 | 3372 |

2 | mnbvmar | 3345 |

3 | OO0OOO00O0OOO0O0…O | 3264 |

4 | Radewoosh | 3230 |

5 | scott_wu | 3189 |

6 | Benq | 3187 |

7 | LHiC | 3171 |

8 | Um_nik | 3155 |

9 | V--o_o--V | 3152 |

10 | Petr | 3139 |

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

1 | Radewoosh | 191 |

2 | Errichto | 172 |

3 | rng_58 | 159 |

4 | neal | 156 |

5 | Um_nik | 154 |

5 | tourist | 154 |

7 | Ashishgup | 151 |

7 | Petr | 151 |

7 | PikMike | 151 |

10 | 300iq | 150 |

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: Nov/17/2018 06:43:03 (f2).

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.