Mike and Fraud

3.3

13 votes
Binary search algorithm, Medium, Recruit, Prime Factorization, Segment tree, Mathematics, Open, Approved, Mathematics, Mathamatics
Problem

Mike Ross is a fraud!. That's what the world says. However, Harvey is highly disagreeable to this, and feels that Mike did what he had to, only for the good of the world.

Tired of constant criticism, Harvey decides to prove to the world, what a great friend he is. Travis Tanner, being his Biggest competitor, challenges him to the following task :

Given an array A of size N and an integer K, can you find the number of good sub-arrays of this array? A sub-array is a contiguous subsequence of an array, and is considered to be good, if the product of all integers it contains is divisible by K.

Harvey is completely bowled over by the difficulty of this task, as he is not a very math oriented person, and needs your help urgently. Can you find the answer ?

Input Format :

The first line contains 2 space separated integers N and K. The next line contains N space separated integers denoting the elements of array A.

Output Format:

Print the required answer on a single line.

Constraints:

1N2×105

1K109

1A[i]109

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

The subarray from 2 to 3 is one of the subarrays divisble by 6, as 2×3=6, and 6 is divisible by 6.

Editor Image

?