#K36417. Maximum Distinct Fruits

    ID: 25750 Type: Default 1000ms 256MiB

Maximum Distinct Fruits

Maximum Distinct Fruits

Given an integer N representing the number of fruits and an integer K representing a multiplication factor, along with a list of N fruit weights, determine the maximum number of distinct fruits that can be obtained by forming multiplication chains. For a fruit of weight \( w \), if there exists a fruit with weight \( w \times K \), then it is considered part of the chain. Continue this process iteratively until the product is no longer present in the list.

Note that each fruit weight is counted only once irrespective of duplicate entries. The final answer is the number of distinct fruit weights (including those appearing in the chains) that exist in the input.

inputFormat

The input consists of two lines. The first line contains two integers ( N ) and ( K ). The second line contains ( N ) space-separated integers representing the weights of the fruits.

outputFormat

Output a single integer representing the maximum number of distinct fruits obtainable based on the multiplication chain condition.## sample

5 2
1 2 4 8 16
5