【题目大意】

给n个数判断有几个素数。(每个数<=2^32)

注意多组数据

【题解】

用Rabin_Miller测试跑得飞快。。。

 /*************
HDU 2138
by chty
2016.11.5
*************/
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cmath>
#include<algorithm>
using namespace std;
typedef long long ll;
ll n,ans;
inline ll read()
{
ll x=,f=; char ch=getchar();
while(!isdigit(ch)) {if(ch=='-') f=-; ch=getchar();}
while(isdigit(ch)) {x=x*+ch-''; ch=getchar();}
return x*f;
}
ll fast(ll a,ll b,ll mod) {ll sum=;for(;b;b>>=,a=a*a%mod)if(b&)sum=sum*a%mod;return sum;}//一行快速幂
bool Rabin_Miller(ll p,ll a)
{
if(p==) return ;
if(p&==||p==) return ;
ll d=p-;
while(!(d&)) d>>=;
ll m=fast(a,d,p);
if(m==) return ;
while(d<p)
{
if(m==p-) return ;
d<<=;
m=m*m%p;
}
return ;
}
bool isprime(ll x)
{
static ll prime[]={,,,,,,,,};
for(ll i=;i<;i++)
{
if(x==prime[i]) return ;
if(!Rabin_Miller(x,prime[i])) return ;
}
return ;
}
int main()
{
freopen("cin.in","r",stdin);
freopen("cout.out","w",stdout);
while(~scanf("%lld",&n))
{
ans=;
for(ll i=;i<=n;i++)
{
ll x=read();
if(isprime(x)) ans++;
}
printf("%lld\n",ans);
}
return ;
}

【HDU2138】How many prime numbers的更多相关文章

  1. 【ACM】How many prime numbers

    http://acm.hdu.edu.cn/game/entry/problem/show.php?chapterid=2&sectionid=1&problemid=2 #inclu ...

  2. 【BZOJ1662】[Usaco2006 Nov]Round Numbers 圆环数 数位DP

    [BZOJ1662][Usaco2006 Nov]Round Numbers 圆环数 Description 正如你所知,奶牛们没有手指以至于不能玩"石头剪刀布"来任意地决定例如谁 ...

  3. 【CF653G】Move by Prime 组合数

    [CF653G]Move by Prime 题意:给你一个长度为n的数列$a_i$,你可以进行任意次操作:将其中一个数乘上或者除以一个质数.使得最终所有数相同,并使得操作数尽可能小.现在我们想要知道$ ...

  4. 【LeetCode】165. Compare Version Numbers 解题报告(Python)

    [LeetCode]165. Compare Version Numbers 解题报告(Python) 标签(空格分隔): LeetCode 作者: 负雪明烛 id: fuxuemingzhu 个人博 ...

  5. 【Codeforces 385C】Bear and Prime Numbers

    [链接] 我是链接,点我呀:) [题意] f[i]表示在x[]中有多少个数字是i的倍数 让你求出sum(f[i]) li<=i<=ri 且i是质数 [题解] 做筛法求素数的时候顺便把素数i ...

  6. 【leetcode】Bitwise AND of Numbers Range(middle)

    Given a range [m, n] where 0 <= m <= n <= 2147483647, return the bitwise AND of all numbers ...

  7. 【LeetCode】165 - Compare Version Numbers

    Compare two version numbers version1 and version2.If version1 > version2 return 1, if version1 &l ...

  8. 【leetcode】448. Find All Numbers Disappeared in an Array

    problem 448. Find All Numbers Disappeared in an Array solution: class Solution { public: vector<i ...

  9. 【Leetcode】445. Add Two Numbers II

    You are given two non-empty linked lists representing two non-negative integers. The most significan ...

随机推荐

  1. apache phoenix 安装试用

    备注:   本次安装是在hbase docker 镜像的基础上配置的,主要是为了方便学习,而hbase搭建有觉得   有点费事,用镜像简单.   1. hbase 镜像 docker pull har ...

  2. spring整合xfire出现Document root element "beans", must match DOCTYPE root "null"错误解决方案

    fire自带的包下有个spring1.2.6的jar包,而工程的jar包是2.0的. 解决方案: 1.将原配置文件的头schema方式换为DOCTYPE方式,原配置文件如下(非maven) <? ...

  3. 11.Python使用Scrapy爬虫小Demo(新手入门)

    1.前提:已安装好scrapy,且已新建好项目,编写小Demo去获取美剧天堂的电影标题名 2.在项目中创建一个python文件 3.代码如下所示: import scrapy class movies ...

  4. java入门很简单之各种循环

    1.if结构的语法: <1> 简单的if :if (条件){ //代码块                                                           ...

  5. 函数参数个数不确定时使用va_start

    今天在网上看程序时忽然发现别人的函数参数中有省略号,甚是吃惊,发现其函数中使用了va_start,经过查资料大概明白其用法,个人觉得很好用! #include <stdio.h> #inc ...

  6. pat1022__字符串查找

    主要是对字符串的查找,为了方便并且快速的实现查找,用map会比较方便 同时如何把一个带有空格的字符串变成多个单词也有一个小技巧 char *point=book[i].keyWord;//关键词分离 ...

  7. MySQL COUNT(*) & COUNT(1) & COUNT(col) 比较分析

    在面试的时候我们会经常遇到这个问题: MySQL 中,COUNT(*).COUNT(1).COUNT(col) 有区别吗? 有区别. 接下来我们分析一下这三者有什么样的区别. 一.SQL Syntax ...

  8. 小峰Hibernate简介与HelloWorld

    一.Hibernate简介: 二.Hibernate4 版Hello World 实现 工程结构: com.cy.model.Student: package com.cy.model; public ...

  9. Charles-断点

    一.添加Charles断点 1.用Charles抓包发起一次接口请求 2.对要打断点的接口右键,选择[Breakpoints] 二.Charles断点设置 1.点击Charles菜单-[Proxy]- ...

  10. php 数组去重 (一维数组与二维数组)

    数组中重复项的去除 一维数组的重复项: 使用array_unique函数即可,使用实例如下: <?php                   $aa=array("apple" ...