米勒罗宾素数测试:

/*
if n < 1,373,653, it is enough to test a = 2 and 3.
if n < 9,080,191, it is enough to test a = 31 and 73.
if n < 4,759,123,141, it is enough to test a = 2, 7, and 61.
if n < 2,152,302,898,747, it is enough to test a = 2, 3, 5, 7, and 11.
*/
#include <cstdio>
long long power(long long m,long long n,long long k)
{
long long b = ;
while (n>)
{
if (n&) b=(b*m)%k;
n=n>>;
m=(m*m)%k;
}
return b;
} bool Miller_Rabbin(long long t)
{
if (t==) return true;
if (power(,t-,t)!=) return false;
if (power(,t-,t)!=) return false;
if (power(,t-,t)!=) return false;
return true;
} int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
int x,ans;
ans=;
for (int i=; i<n; i++)
{
scanf("%d",&x);
if (Miller_Rabbin(x)) ans++;
}
printf("%d\n",ans);
}
}

HDU 2138 How many prime numbers的更多相关文章

  1. HDOJ(HDU) 2138 How many prime numbers(素数-快速筛选没用上、)

    Problem Description Give you a lot of positive integers, just to find out how many prime numbers the ...

  2. HDU 2138 How many prime numbers(Miller_Rabin法判断素数 【*模板】 用到了快速幂算法 )

    How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  3. HDU 2138 How many prime numbers (判素数,米勒拉宾算法)

    题意:给定一个数,判断是不是素数. 析:由于数太多,并且太大了,所以以前的方法都不适合,要用米勒拉宾算法. 代码如下: #include <iostream> #include <c ...

  4. 【HDU】2138 How many prime numbers

    http://acm.hdu.edu.cn/showproblem.php?pid=2138 题意:给n个数判断有几个素数.(每个数<=2^32) #include <cstdio> ...

  5. hdu 5108 Alexandra and Prime Numbers(水题 / 数论)

    题意: 给一个正整数N,找最小的M,使得N可以整除M,且N/M是质数. 数据范围: There are multiple test cases (no more than 1,000). Each c ...

  6. hdu 5108 Alexandra and Prime Numbers

    数论题,本质是求出n的最大质因子 #include<time.h> #include <cstdio> #include <iostream> #include&l ...

  7. How many prime numbers(素数)

    Problem Description   Give you a lot of positive integers, just to find out how many prime numbers t ...

  8. 【HDU2138】How many prime numbers

    [题目大意] 给n个数判断有几个素数.(每个数<=2^32) 注意多组数据 [题解] 用Rabin_Miller测试跑得飞快... /************* HDU 2138 by chty ...

  9. hdoj--2138--How many prime numbers(暴力模拟)

    How many prime numbers Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

随机推荐

  1. IOS8 设置TableView Separatorinset 分割线从边框顶端开始

    IOS8 设置TableView Separatorinset 分割线从边框顶端开始   在ios8上 [TableViewsetSeparatorInset:UIEdgeInsetsMake(0,0 ...

  2. 数字运算、ASCII

    num20 = dollar/20;num10 = (dollar - 20*num20)/10;num5 =(dollar-20*num20-10*num10)/5;//可以写为num5 = (do ...

  3. IOS 特定于设备的开发:获取额外的设备信息

    sysctl()和sysctlbyname()允许获取系统信息.这些标准的UNIX函数用于询问操作系统有关硬件和OS的详细信息. 这些常量使你能够检查核心信息,比如系统的CPU频率,可用的内存量等.它 ...

  4. 帝国cms中上一篇与下一篇个性化灵动标签调出

    这里的上下篇是用灵动标签制作,可以更为个性化 下一篇 <a href="<?phpecho $bqsr[titleurl];$next='true';?>"> ...

  5. nmon related

    nmon related pGraph (supports nmon) https://www.ibm.com/developerworks/community/wikis/home?lang=en# ...

  6. VIPS: a VIsion based Page Segmentation Algorithm

    VIPS: a VIsion based Page Segmentation Algorithm VIPS: a VIsion based Page Segmentation Algorithm In ...

  7. kbengine环境搭建(2)

    做好准备工作后,可以开始搭建我们的kbengine服务端,运行成功kbengine服务端,共有9个服务会相应的被打开,并会全部提示[info]found all components! 准备工作 1. ...

  8. Good Luck in CET-4 Everybody!(博弈)

    Good Luck in CET-4 Everybody! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. RabbitMQ(2)

    上一次安装了RabbitMQ并成功创建了vhost和user,可是生产和消费的过程还没有完毕.这次主要调了一下这个过程. 上次基本的问题是没有实现过程代码的编写保存,事实上也就是Python程序,这两 ...

  10. CSS 布局总结——固定宽度布局

    固定宽度布局 单列布局 watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2Fyd29sZjI0/font/5a6L5L2T/fontsize/400/fil ...