SCU - 4489 misaka and last order【枚举因子】



Time Limit: 1000 MS    Memory Limit: 131072 K 


    

Description

Misaka Mikoto is a main character of the Animation "To Aru Majutsu no Index" and "To Aru Kagaku no Railgun". She was enrolled into the Academy City to train herself and had been working very hard until she was ranked Level 5, which is regarded as the highest ranking around the city. By the way, there are only seven people who reached that level, and she won the third place. Now, she is the best "Electromaster" in Academy City. Mikoto's unique skill is to shoot metal objects such as coins at a high speed, destructively. Hence, she finally gained a nickname, "Railgun" (超電磁砲 (レールガン) . Mikoto attended Tokiwadai Middle School,which is a famous girls' secondary school for the rich and elites and was acknowledged as one of the five famous schools in the Academy City. To most people, she is considered a typical lady, but in reality, she is short-tempered, prideful, and greatly interested in some childish things. Misaka has many sisters, they are Misaka's clones. Unlike Mikoto, they seem rather quiet and emotionless, their voices are rather monotonous and computer-like, and they speak in third person by adding a description of themselves after every sentence. In addition, they wear a special set of goggles that enables them to see electron beams and magnetic field lines for the reason that, unlike Mikoto, they do not have that ability. Misaka clone No. 20001(Last order, 打ち止め, 最终之作). She is the administrator of the Misaka Network and the fail-safe mechanism in case the Sisters go out of control. She is not designed to function independently and survive for long outside a culture container and appears to be only about ten years old. Misaka finds that all her sisters were trapped in a laboratory. Accelerator(一方通行 ,アクセラレータ) is going to kill them!! She must take actions to save them. Last order tells her that she may not take all the sisters away. Each sister has an electronic value a. If the GCD(Greatest Common Divisor) of some sisters’ value is greater than m (if only one sister was chosen, the GCD is the electronic value of herself), then these sisters can be taken away. Misaka wants to save as many sisters as possible. Please help her!!

Input

In the first line, there is an integer T, indicating the number of test cases. The next T cases follow. For the first line, there are two integer n and m, n is the number of the sisters, m is the GCD limit.(1 <= n, m <= 1000000) Then another line shows n integer, represents all the electronic values of all the sisiters.(1 <= values <= 1000000)

Output

Output one line for each test case. Just print the max number of sisters which Misaka can save.

Sample Input

3 3 1 1 2 3 3 2 1 2 4 3 4 1 3 5

Sample Output

3 2 1

Hint

For the third case, Misaka can only choose the third sister.

Author

love_kd

思路:

求最多选多少个数,它们的最大公约数大于等于m。用一个数组记录每个数出现的次数,然后枚举因子和倍数即可。


代码:

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int n,m,a[1000005],dis[1000005];
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        scanf("%d%d",&n,&m);
        int maxx=0;
        memset(dis,0,sizeof dis);
        for(int i=0;i<n;i++)
        {
            scanf("%d",&a[i]);
            dis[a[i]]++;
            maxx=max(maxx,a[i]);
        }
        int ans=0;
        for(int i=m;i<=maxx;i++)
        {
            int s=0;
            for(int j=1;i*j<=1000000;j++)
                s+=dis[i*j];
            ans=max(ans,s);
        }
        printf("%d\n",ans);
    }
    return 0;
}


Time Limit: 1000 MS    Memory Limit: 131072 K 


    

Description

Misaka Mikoto is a main character of the Animation "To Aru Majutsu no Index" and "To Aru Kagaku no Railgun". She was enrolled into the Academy City to train herself and had been working very hard until she was ranked Level 5, which is regarded as the highest ranking around the city. By the way, there are only seven people who reached that level, and she won the third place. Now, she is the best "Electromaster" in Academy City. Mikoto's unique skill is to shoot metal objects such as coins at a high speed, destructively. Hence, she finally gained a nickname, "Railgun" (超電磁砲 (レールガン) . Mikoto attended Tokiwadai Middle School,which is a famous girls' secondary school for the rich and elites and was acknowledged as one of the five famous schools in the Academy City. To most people, she is considered a typical lady, but in reality, she is short-tempered, prideful, and greatly interested in some childish things. Misaka has many sisters, they are Misaka's clones. Unlike Mikoto, they seem rather quiet and emotionless, their voices are rather monotonous and computer-like, and they speak in third person by adding a description of themselves after every sentence. In addition, they wear a special set of goggles that enables them to see electron beams and magnetic field lines for the reason that, unlike Mikoto, they do not have that ability. Misaka clone No. 20001(Last order, 打ち止め, 最终之作). She is the administrator of the Misaka Network and the fail-safe mechanism in case the Sisters go out of control. She is not designed to function independently and survive for long outside a culture container and appears to be only about ten years old. Misaka finds that all her sisters were trapped in a laboratory. Accelerator(一方通行 ,アクセラレータ) is going to kill them!! She must take actions to save them. Last order tells her that she may not take all the sisters away. Each sister has an electronic value a. If the GCD(Greatest Common Divisor) of some sisters’ value is greater than m (if only one sister was chosen, the GCD is the electronic value of herself), then these sisters can be taken away. Misaka wants to save as many sisters as possible. Please help her!!

Input

In the first line, there is an integer T, indicating the number of test cases. The next T cases follow. For the first line, there are two integer n and m, n is the number of the sisters, m is the GCD limit.(1 <= n, m <= 1000000) Then another line shows n integer, represents all the electronic values of all the sisiters.(1 <= values <= 1000000)

Output

Output one line for each test case. Just print the max number of sisters which Misaka can save.

Sample Input

3 3 1 1 2 3 3 2 1 2 4 3 4 1 3 5

Sample Output

3 2 1

Hint

For the third case, Misaka can only choose the third sister.

Author

love_kd
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值