hdu2138 How many prime numbers 米勒测试
hdu2138 How many prime numbers
#include <bits/stdc++.h>
using namespace std;
typedef long long ll; ll prime[] = {,,,,};
ll qmul(ll a, ll b, ll mod) {
ll res = ;
while (b) {
if (b&) res = (res+a)%mod;
a = (a+a)%mod;
b >>= ;
}
return res;
}
ll qpow(ll a, ll b, ll mod) {
ll res = ;
while (b) {
if (b&) res = qmul(res,a,mod);
a = qmul(a,a,mod);
b >>= ;
}
return res;
}
bool Miller_Rabin(ll p) {
if (p < ) return ;
if (p != && p % == ) return false;
ll s = p-;
while (!(s&)) s >>= ;
for (int i = ; i < ; i++) {
if (p == prime[i]) return true;
ll t = s, m = qpow(prime[i],s,p);
while (t != p- && m != && m != p-) {
m = qmul(m,m,p);
t <<= ;
}
if (m != p- && !(t&)) return false;
}
return true;
}
int main() {
int n;
while (~scanf("%d",&n)) {
int ans = ;
for (int i = ; i <= n; i++) {
ll x; scanf("%lld",&x);
if (Miller_Rabin(x)) ans++;
}
printf("%d\n",ans);
}
return ;
}
hdu2138 How many prime numbers 米勒测试的更多相关文章
- Project Euler 41 Pandigital prime( 米勒测试 + 生成全排列 )
题意:如果一个n位数恰好使用了1至n每个数字各一次,我们就称其为全数字的.例如,2143就是一个4位全数字数,同时它恰好也是一个素数. 最大的全数字的素数是多少? 思路: 最大全排列素数可以从 n = ...
- 2018.12.17 hdu2138 How many prime numbers(miller-rbin)
传送门 miller−rabbinmiller-rabbinmiller−rabbin素数测试的模板题. 实际上miller−rabinmiller-rabinmiller−rabin就是利用费马小定 ...
- [HDU2138]How many prime numbers
来源: HDU 2007-11 Programming Contest_WarmUp 题目大意:素数判定. 思路: 事实上暴力判定也可以过,但我还是用了Miller-Rabin算法. 核心思想:利用费 ...
- CSU 1552 Friends(二分图 + 米勒测试)
题目链接:http://acm.csu.edu.cn/csuoj/problemset/problem?pid=1552 Description On an alien planet, every e ...
- poj 2739 Sum of Consecutive Prime Numbers 尺取法
Time Limit: 1000MS Memory Limit: 65536K Description Some positive integers can be represented by a ...
- Project Euler 27 Quadratic primes( 米勒测试 + 推导性质 )
题意: 欧拉发现了这个著名的二次多项式: f(n) = n2 + n + 41 对于连续的整数n从0到39,这个二次多项式生成了40个素数.然而,当n = 40时402 + 40 + 41 = 40( ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- algorithm@ Sieve of Eratosthenes (素数筛选算法) & Related Problem (Return two prime numbers )
Sieve of Eratosthenes (素数筛选算法) Given a number n, print all primes smaller than or equal to n. It is ...
随机推荐
- php 通过 yield 实现协程有什么使用场景
来源:https://segmentfault.com/q/1010000010018151 参考:https://www.cnblogs.com/lynxcat/p/7954456.html 协程可 ...
- 关于virtualbox配置centos7的网络问题
连接方式最好选桥接网卡 原文:https://www.cnblogs.com/zergling9999/p/6026006.html
- 在 ubuntu20 上替换原有的源,解决下载软件慢的问题
处理方式 使用命令查看到所有的下载源 sudo gedit /etc/apt/sources.list 使用163的源替换掉原始的源 163:http://mirrors.163.com/ubuntu ...
- 表达式求值--数据结构C语言算法实现
这篇博客介绍的表达式求值是用C语言实现的,只使用了c++里面的引用. 数据结构课本上的一个例题,但是看起来很简单,实现却遇到了很多问题. 这个题需要构建两个栈,一个用来存储运算符OPTR, 一个用来存 ...
- MFC之动态调用自己写的类库中的类的成员方法
第一步:创建一个要调用的类库 如果是MFC程序使用,可以创建一个MFC的类库,不过依然可以创建一个win32类库.我所知道的,MFC的类库可以分为常规MFC DLL和MFC扩展DLL关于它们之间的区别 ...
- nodejs操作MySQL,mysql连接池及事务的使用
https://blog.csdn.net/jasnet_u/article/details/88605168
- 数据库SQL语言从入门到精通--Part 4--SQL语言中的模式、基本表、视图
数据库从入门到精通合集(超详细,学习数据库必看) 前言: 使用SQL语言时,要注意SQL语言对大小写并不敏感,一般使用大写.所有符号一定是西文标点符号(虽然是常识,但我还是提一嘴) 1.模式的定义与删 ...
- 数学--数论--HDU2136 Largest prime factor 线性筛法变形
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- AWVS 安全渗透扫描
1.打开软件,点击 New Scan 2.在 website url 中输入被扫描的网址,点击 next 3.在 scanning profile 中选择测试的漏洞类型,默认选择 default(默认 ...
- xenomai内核解析之xenomai的组成结构
@ 目录 一.xenomai 3 二.xenomai3 结构 这是第二篇笔记. 一.xenomai 3 从xenomai3开始支持两种方式构建linux实时系统,分别是cobalt 和 mercury ...