Shil and Lab Assignment

3.6

9 votes
Approved, Graphs, Matching, Math, Medium, Ready
Problem

For the lab assignment of this week , Shil got N numbers A1 , A2, ... AN. He must assign each of these numbers a unique integer value from 1 to M. Let Ci be the integer assigned to Ai . Shil must assign numbers in such a way that maximum number of Ai are divisible by their Ci . You must print maximum numbers of Ai that could be made divisible by Ci in optimal assignment.

Input:
First Line of input consists of integer N and M.
Next N lines consists of N integers with ith line containing integer Ai.

Output:
Output maximum number of Ai that can be made divisible by Ci in optimal assignment.

Constraints:

  • 1N103
  • 1Ai105
  • NM105
Time Limit: 1
Memory Limit: 256
Source Limit:
Explanation

Some of the possible assignments are [8,2,4,1,5] , [8,2,4,1,6] or [7,2,4,1,8]

Editor Image

?