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.

#include<queue>
#include<stack>
#include<vector>
#include<math.h>
#include<cstdio>
#include<numeric>//STL数值算法头文件
#include<stdlib.h>
#include<string.h>
#include<iostream>
#include<algorithm>
#include<functional>//模板类头文件
using namespace std; const int INF=1e9+7;
const int maxn=1010000;
typedef long long ll; //(筛法的活用)
//首先这一道题讲的是n个数与m的关系,仔细想想
//如果某几个数的gcd是m,那么这几个数肯定是m的倍数,这就是筛法的巧妙之处
//既可以筛出素数,也可以筛出一个数的倍数,放在这一题中,从最小的m开始找,
//把从** m **到*** n个数中的最大数为终点 **范围内的所有m的倍数都找出来
//之前用桶排的思想把出现的数某个的** 次数 **记录下来,如果某个数
//** 是m的倍数,且在这n个数中 **,则把这个数的频数加起来,最后结果就是答案
int n,m,t;
int vis[maxn];
int main()
{
scanf("%d",&t);
while(t--)
{
memset(vis,0,sizeof(vis));
int maxx=0,a;
scanf("%d%d",&n,&m);
for(int i=0; i<n; i++)
{
scanf("%d",&a);
vis[a]++;
maxx=max(maxx,a);
}
int ans=0;
for(int i=m; i<=maxx; i++)
{
int cnt=0;
for(int j=1; j<=maxx; j++)
{
int temp=i*j;
if(temp>maxx)
break;
cnt+=vis[temp];
}
ans=max(cnt,ans);
}
printf("%d\n",ans);
}
return 0;
}

misaka and last order SCU - 4489 (筛法的灵活应用)的更多相关文章

  1. Heritrix源码分析(七) Heritrix总体介绍(转)

    本博客属原创文章,欢迎转载!转载请务必注明出处:http://guoyunsky.iteye.com/blog/642794         本博客已迁移到本人独立博客: http://www.yun ...

  2. 【转】SQL常用的语句和函数

    原文链接:http://www.cnblogs.com/mailingfeng/archive/2013/01/07/2850116.html order by 的数值型灵活使用 select * f ...

  3. SQL常用的语句和函数

    order by 的数值型灵活使用 select * from table_a where order by decode(函数,'asc',1,'desc',-1)*jsny; 控制试图的访问时间: ...

  4. 使用CSS灵活的盒子

    CSS3灵活的盒子,或flexbox,是一个布局模式提供页面上的元素的安排这样的元素表现可以预见当页面布局必须适应不同屏幕大小和不同的显示设备.对于许多应用程序,灵活的块盒模型提供了一个改进模型,它不 ...

  5. POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)

    POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...

  6. POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离)

    POJ 2502 Subway / NBUT 1440 Subway / SCU 2186 Subway(图论,最短距离) Description You have just moved from a ...

  7. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  8. HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)

    HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...

  9. HDU 4489 The King’s Ups and Downs dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4489 The King's Ups and Downs Time Limit: 2000/1000 ...

随机推荐

  1. display:inline-block之用法

    HTML的元素有多种display属性,比较常见的有display:none; display:block; display:inline和display:inline-block;等.详细可参阅W3 ...

  2. ELK 企业内部日志分析系统

    生产环境配置 亿级规模,建议64G内存+8核CPU ES JVM占用一半内存 生产环境的3节点的集群 https://blog.csdn.net/xuduorui/article/details/79 ...

  3. JavaScript:详解 Base64 编码和解码

    Base64是最常用的编码之一,比如开发中用于传递参数.现代浏览器中的<img />标签直接通过Base64字符串来渲染图片以及用于邮件中等等.Base64编码在RFC2045中定义,它被 ...

  4. LintCode 397: Longest Increasing Continuous Subsequence

    LintCode 397: Longest Increasing Continuous Subsequence 题目描述 给定一个整数数组(下标从0到n - 1,n表示整个数组的规模),请找出该数组中 ...

  5. SDUT 3929

    Description 蓝色空间号和万有引力号进入了四维水洼,发现了四维物体--魔戒. 这里我们把飞船和魔戒都抽象为四维空间中的一个点,分别标为 "S" 和 "E&quo ...

  6. 机器学习-kNN-寻找最好的超参数

    一 .超参数和模型参数 超参数:在算法运行前需要决定的参数 模型参数:算法运行过程中学习的参数 - kNN算法没有模型参数- kNN算法中的k是典型的超参数 寻找好的超参数 领域知识 经验数值 实验搜 ...

  7. 知乎大神对IAAS,SAAS,PAAS区别的理解

    你一定听说过云计算中的三个“高大上”的你一定听说过云计算中的三个“高大上”的概念:IaaS.PaaS和SaaS,这几个术语并不好理解.不过,如果你是个吃货,还喜欢披萨,这个问题就好解决了!好吧,其实你 ...

  8. bootstrap入门项目备份

    bootstrap入门项目备份 http://files.cnblogs.com/files/wordblog/bootstrap%E5%85%A5%E9%97%A8%E9%A1%B9%E7%9B%A ...

  9. 一起来学redis(一)

    redis是一个开源的,高性能的,基于键值对的缓存与存储系统通过提供多种键值数据类型来适应不同场景下的缓存与存储需求. 同时redis的诸多高层级功能使其可以胜任消息队列,任务队列等不同的角色. 特性 ...

  10. 关于分布式Session 的几种实现方式

    分布式Session的几种实现方式 1.基于数据库的Session共享 2.基于NFS共享文件系统 3.基于memcached 的session,如何保证 memcached 本身的高可用性? 4. ...