report VI VI EN
Register | Login
  • HOME
  • PROBLEMSET
  • ROADMAP
  • COMPETITION
  • TOPIC
  • RANKING
  • GUIDE
  • MASHUP
  • ABOUT
  • CONTACT
  • Problem
  • Submit
  • Results
GCD pairs counting - MarisaOJ: Marisa Online Judge

GCD pairs counting

Time limit: 1000 ms
Memory limit: 256 MB
Given a sequence of integers $A$ consisting of n elements. For each integer $i$ from $1$ to $n$, count how many pairs of integers in sequence A have the greatest common divisor (GCD) equal to $i$. ### Input - The first line contains an integer $n$. - The second line contains n integers $A_i$. ### Output - Output $n$ integers, where the $i^{th}$ integer is the number of pairs of integers with the GCD equal to $i$. ### Constraints - $1 \le n \le 10^6$. - $1 \le A_i \le n$ ### Example Input: ``` 8 5 1 5 6 8 8 3 5 ``` Output: ``` 21 2 1 0 3 0 0 1 ```
Inclusion-exclusion principle
Divisibility
Divisibility 2
Coprime query
GCD pairs counting
Good string pairs
Permutation problem
Restricted equation
Moving through matrix
Restricted equation 2
Binary matrix 2
Permutation Counting 2
Topic
Math
Rating 1500
Solution (0) Solution