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;
}

转载于:https://www.cnblogs.com/nyist-xsk/p/7264852.html

misaka and last order SCU - 4489 (筛法的灵活应用)相关推荐

  1. 基于若依框架的二次开发_SAP Commerce(原Hybris)的订单处理框架和SAP CRM One Order框架...

    最近工作重点转移到了SAP Commerce上来,正好有机会把该产品里由Java实现的订单处理框架和我之前长期工作过的,ABAP实现的SAP CRM One Order框架做个比较:基于Spring的 ...

  2. SAP Commerce(原Hybris)的订单处理框架和SAP CRM One Order框架

    最近工作重点转移到了SAP Commerce上来,正好有机会把该产品里由Java实现的订单处理框架和我之前长期工作过的,ABAP实现的SAP CRM One Order框架做个比较:基于Spring的 ...

  3. ggcor |相关系数矩阵可视化

    厚缊 业余的R语言可视化重度患者 个人博客:houyun.xyz 邮箱:houyunhuang@163.com 转载本文(包括长期转载账号)必须联系厚缊授权 相关系数矩阵可视化已经至少有两个版本的实现 ...

  4. 从混合云存储看阿里云对下一代企业计算架构的思考

    摘要:在公共云视角下,把企业本地存储视为一整套存储与计算方案中的一个部分与环节,通过公共云对云上云下存储和计算统一管理,以满足脉冲计算.基因计算.AI与机器学习等新型计算与数据存储的需求,这就是阿里云 ...

  5. 【SQL语句】灵活SQL语句

    1.查询数学成绩排名 select ss.stid, ss.name, ss.score, (select count(*) from stuscore s where s.subject='数学' ...

  6. MyBatis Dynamic SQL(一)— 真正的Mybatis动态sql — MyBatis Dynamic SQL

    目录 现状 MyBatis Dynamic SQL 项目地址 官方文档 项目介绍 作者 Mybatis Generator 简介 特性 目标 提示 快速使用 步骤 定义常量Tables和Columns ...

  7. SQL全方位攻略:3.SQL标准

    系列文章目录 1.数据库介绍 2.SQL介绍 文章目录 系列文章目录 3. SQL标准 3.1 ISO SQL和ANSI SQL 3.2 SQL标准的历史 1. SQL-86 2. SQL-89 (S ...

  8. Smark.Data 功能强大又灵活的Expression

    Expression对象是Smark.Data的核心对象,虽然Expression是个条件对象,但它所具备的功能是你想象不到的:),以下把Expression的功能列出来. public RESULT ...

  9. UVA516 POJ1365 LA5533 ZOJ1261 Prime Land【欧拉筛法】

    Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...

最新文章

  1. 思科:四分之三的物联网项目将以失败告终
  2. UWP 图片剪切旋转工具
  3. wxWidgets:将 PNG 图像文件包含到可执行文件中
  4. 全局稳定性收敛平衡点为0吗_该平衡点处的小扰动稳定性判据是什?
  5. 用户研究:如何做用户画像分析
  6. java类spring加载_spring的加载机制?
  7. 8、饼图(ax.pie)
  8. Windows Server 2008 R2之三十八 Hyper-V的授权管理
  9. 口袋妖怪模拟器android,口袋妖怪叶绿模拟器手机版
  10. 证券词汇集锦(中英文+注释版)
  11. java根据cookie统计uv,利用Cookie统计UV流量 | 学步园
  12. 手机端获取用户详细地理位置(腾讯地图/高德)
  13. 小饭馆促销活动流程,小饭馆网络营销方案
  14. 真杜比全景声家庭影院级投影设备,当贝做到了五千元内也支持
  15. Java OCR 图像智能字符识别技术,可识别中文
  16. 怎么把好几行弄成一行_将多行内容合并成一行的两种方式
  17. 什么是mysql 中级工程师的理解
  18. C语言适合什么开发,1.1.3 C语言适合什么开发
  19. 【Apache POI】Excel操作(一):Excel本地写入基本操作的实现
  20. PHP+MySQL编写人事公司员工工资管理系统

热门文章

  1. 【西川善司的3D图形技术连载】3D图形的概念和渲染管线(Render Pipeline)(9~13回)
  2. Docker部署ELK(ElasticSearch logstash Kibana)
  3. TR069协议与商业应用1——概述(带目录索引)
  4. c# urlencode空格变成+_URL 传+号到后台变空格问题解决方案 | YuXi
  5. Revit(9)-元素-元素的获取
  6. 好看的鼠标hover效果
  7. 个推消息推送SDK之“富媒体样式”功能详解
  8. 网络API接口的详细使用
  9. 使用反向代理规避备案风险
  10. 基于冲突搜索的多机器人路径规划(Matlab代码实现)