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

2 | Radewoosh | 3468 |

3 | Um_nik | 3429 |

4 | Petr | 3354 |

5 | Benq | 3286 |

6 | mnbvmar | 3280 |

7 | wxhtxdy | 3276 |

7 | LHiC | 3276 |

9 | ecnerwala | 3214 |

10 | yutaka1999 | 3190 |

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

1 | Errichto | 191 |

2 | Radewoosh | 180 |

3 | tourist | 173 |

4 | PikMike | 165 |

4 | Vovuh | 165 |

4 | antontrygubO_o | 165 |

7 | rng_58 | 161 |

8 | Um_nik | 157 |

9 | majk | 156 |

10 | 300iq | 155 |

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-2019 Mike Mirzayanov

The only programming contests Web 2.0 platform

Server time: Oct/20/2019 05:25:08 (f3).

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.can you please provide that solution