
米勒罗宾算法:判断一个大数是不是素数
���������������������������������������������������������10,000��������������������������������������������������������������������������������� ������������������������������������������������������������������������������������ ���������������������������������������n������������������������������������p���������n-p������������������������������������������������������������
发布日期:2021-05-10 16:09:30
浏览次数:19
分类:精选文章
本文共 3327 字,大约阅读时间需要 11 分钟。
������������������������
���������������������
������������������������������������������������������������������������������������������������������������2������������������������������������������������������������������������������������������������������C++���������
������������
������������������������������������������
- ���������������������������������������������������������������������������������������ctime���������������������
- ������������������������Miller-Rabin���������������������������������������������������������������������������������������������������������������������
- ���������������������������������������������������������10,000���������������������������������������������������������������������������
- ������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
���������������
������������
#include#include #include #include #include using namespace std;typedef unsigned long long LL;LL qmul(LL x, LL y, LL mod) { return (x * y - (long long)(x / (long double)mod * y + 1e-3) * mod + mod) % mod;}LL qpow(LL a, LL n, LL mod) { LL ret = 1; while (n) { if (n & 1) ret = qmul(ret, a, mod); a = qmul(a, a, mod); n >>= 1; } return ret;}bool Miller_Rabin(LL p) { if (p < 2) return false; if (p != 2 && p % 2 == 0) return false; LL s = p - 1; while (! (s & 1)) s >>= 1; for (int i = 0; i < 5; ++i) { if (prime[i] == p) return true; LL t = s, m = qpow(prime[i], s, p); while (t != p - 1 && m != 1 && m != p - 1) { m = qmul(m, m, p); t >>= 1; } if (m != p - 1 && ! (t & 1)) return false; } return true;}void init() { for (int i = 2; i < N; ++i) { if (!book[i]) { prime1[k++] = i; } for (int j = 2; i * j <= N; ++j) { if (!book[i * j]) { book[i * j] = true; } } }}int main() { init(); int t = 0; LL n; cin >> t; while (t--) { scanf("%llu", &n); bool flag = false; for (int i = 0; i < k; ++i) { if (n - prime1[i] >= 0 && Miller_Rabin(n - prime1[i])) { printf("%d %llu\n", prime1[i], n - prime1[i]); flag = true; break; } } if (!flag) { printf("������������������������������\n"); } } return 0;}
������
���������������������������������������������������������������������������������Miller-Rabin���������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������������
发表评论
最新留言
逛到本站,mark一下
[***.202.152.39]2025年04月10日 01时48分41秒
关于作者

喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
[源码分析] 消息队列 Kombu 之 启动过程
2021-05-09
[源码分析] 消息队列 Kombu 之 Consumer
2021-05-09
[源码分析] 消息队列 Kombu 之 mailbox
2021-05-09
抉择之苦
2021-05-09
wx.NET CLI wrapper for wxWidgets
2021-05-09
ASP.NET MVC Action Filters
2021-05-09
兰州大学百年校庆--风雨百年萃英路
2021-05-09
Service Broker 无法工作的问题修复
2021-05-09
WCF WebHttp Services in .NET 4
2021-05-09
Powershell中禁止执行脚本解决办法
2021-05-09
HTTP协议状态码详解(HTTP Status Code)
2021-05-09
JMeter 中实现发送Java请求
2021-05-09
设计模式点滴
2021-05-09
数据库优化
2021-05-09
[备忘]域用户登陆出现“此工作站和主域间的信任关系失败”错误解决方法
2021-05-09
继续聊WPF——用Blend自定义Listview控件的列表头
2021-05-09
【.net 深呼吸】启动一个进程并实时获取状态信息
2021-05-09
OO_Unit2 多线程电梯总结
2021-05-09