Codeforces 275C Greed

Source: Internet
Author: User

A K-multiple Free set is a set of integers where there are no pair of integers where one is equal to another integer multip Lied by K. That's, there are no two integers x and y (x<y) from the set, such that Y=x K.

You ' re given a set of n distinct positive integers. Your task is to find the size of it's largest k-multiple free subset.

Input

The ' The ' input contains two integers n and K (1≤n≤105,1≤k≤109). The next line contains a list of n distinct positive integers a1,a2,..., a (1≤ai≤109).

The numbers in the lines are separated by single spaces.

Output

On the ' the ' output print ' the size of the largest k-multiple free subset of {A1,A2,..., a}.

Sample Input

Input

6 2

2 3 6 5 4 10

Output

3

Hint

In the sample input one of the possible maximum 2-multiple free subsets are {4, 5, 6}.

Given a set, there is no subset of y = k*x.

Greed: From small to general election past, if selected, then his K *x can not choose, with set mark down

Code:

#include <stdio.h>
#include <string.h>
#include <set>
#include <algorithm>
using namespace std;
  
int N, K, I, J;
Long Long num[100005], ans;
Set<long long> Save;
int main () {
    ans = 0;
    scanf ("%d%d", &n, &k);
    for (i = 0; i < n; i + +) {
        scanf ("%lld", &num[i])
    ;
    Sort (num, num + N);
    for (i = 0; i < n; i + +) {
        if (Save.count (num[i]) = = 0) {
            ans + +;
            Save.insert (num[i] * k);
        }
    printf ("%lld\n", ans);
    return 0;
}

See more highlights of this column: http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.