Divisible Inversions
InterviewTime limit2sMemory limit512 MB
Given a permutation of 1 to n, count pairs i < j where p[i] is a multiple of p[j].
- Level
Medium6 of 10
- Topics
- Array, Math, Number theory, Binary search
- Solved
- No attempts yet
Problem
Recently, Vasya learned how to count the number of inversions in a permutation with a Fenwick tree. Petya considers that an easy problem, so he decided to make a harder one. Petya asked Vasya to count the inversions in which one element divides the other evenly. Formally, given the permutation , the task is to find the number of pairs of indices such that and is a multiple of .
Help Vasya solve this problem.
Input
The first line contains an integer , the length of the permutation (). The second line contains space-separated integers . The given integers are guaranteed to form a permutation of the integers from to .
Output
Print one integer: the number of divisible inversions in the given permutation.