This page is still under construction.

Parts of this page are still being built. What you see may change.

pqr

Time limit2sMemory limit512 MB

Summary
Count index triples p<q<r whose product A[p]*A[q]*A[r] is divisible by K, for N up to 2000.
Level

Medium5 of 10

Topics
Combinatorics, Number theory, Math
Solved
No attempts yet

Problem

You are given an array AA of NN numbers and an integer KK.

Write a program that counts the triples (p,q,r)(p, q, r) with 0≤p<q<r<N0 \le p < q < r < N such that A[p]×A[q]×A[r]A[p] \times A[q] \times A[r] is divisible by KK.

Input

The first line contains NN and KK, separated by a space. (3≤N≤2 0003 \le N \le 2\,000, 1≤K≤1 000 0001 \le K \le 1\,000\,000)

The second line contains the elements of AA in order from A[0]A[0] to A[N−1]A[N-1]. (1≤A[i]≤100 000 0001 \le A[i] \le 100\,000\,000)

Output

Print the number of triples (p,q,r)(p, q, r) with 0≤p<q<r<N0 \le p < q < r < N such that A[p]×A[q]×A[r]A[p] \times A[q] \times A[r] is divisible by KK.

Examples3

  1. Example 1

    Input
    6 30
    31 1 3 7 2 5
    
    Expected output
    1
    
  2. Example 2

    Input
    4 100
    4 5 2 25
    
    Expected output
    2
    
  3. Example 3

    Input
    3 1000000
    100000000 100000000 100000000
    
    Expected output
    1