一些前置知识可以看一下我的联赛前数学知识 如何判断一个数是否为质数 方法一:试除法 扫描\(2\sim \sqrt{n}\)之间的所有整数,依次检查它们能否整除\(n\),若都不能整除,则\(n\)是质数,否则\(n\)是合数. 代码 bool is_prime(int n){ if(n<2) return 0; int m=sqrt(n); for(int i=2;i<=m;i++){ if(n%i==0) return 0; } return 1; } 方法二.线性筛 用 \(O(n)\)…
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #include<cmath> #include<cstdlib> #include<ctime> #define lson l, m, rt<<1 #define rson m+1, r, rt<<1|1 #…
BZOJ 3667: Rabin-Miller算法 Time Limit: 60 Sec  Memory Limit: 512 MBSubmit: 1044  Solved: 322[Submit][Status][Discuss] Description   Input 第一行:CAS,代表数据组数(不大于350),以下CAS行,每行一个数字,保证在64位长整形范围内,并且没有负数.你需要对于每个数字:第一,检验是否是质数,是质数就输出Prime 第二,如果不是质数,输出它最大的质因子是哪个.…
Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29193 Accepted: 7392 Case Time Limit: 4000MS Description Given a big integer number, you are required to find out whether it's a prime number. Input The first line contains the num…
GCD & LCM Inverse Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 9756Accepted: 1819 Description Given two positive integers a and b, we can easily calculate the greatest common divisor (GCD) and the least common multiple (LCM) of a and b.…
Prime Test Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 29193 Accepted: 7392 Case Time Limit: 4000MS Description Given a big integer number, you are required to find out whether it's a prime number. Input The first line contains the num…
Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 6664    Accepted Submission(s): 3997 Problem Description Eddy's interest is very extensive, recently he is interested in prime…
Pollard Rho介绍 Pollard Rho算法是Pollard[1]在1975年[2]发明的一种将大整数因数分解的算法 其中Pollard来源于发明者Pollard的姓,Rho则来自内部伪随机算法固有的循环 Pollard Rho算法在其他因数分解算法[3]中不算太出众,但其空间复杂度Θ(1)的优势和好打的代码使得OIer更倾向于使用Pollard Rho算法 毕竟试除法太慢了,谁没事打Pollard Rho不打试除法 Pollard Rho原理 生日悖论 如果一年只有365天(不计算闰…
\(\text{update 2019.8.18}\) 由于本人将大部分精力花在了cnblogs上,而不是洛谷博客,评论区提出的一些问题直到今天才解决. 下面给出的Pollard Rho函数已给出散点图.关于\(Millar Robin\)算法的时间复杂度在我的博客应该有所备注.由于本人不擅长时间复杂度分析,如果对于时间复杂度有任何疑问,欢迎在下方指出. 1.1 问题的引入 给定一正整数\(N \in \mathbb{N}^*\),试快速找到它的一个因数. 很久很久以前,我们曾学过试除法来解决这…
前言 \(Pollard\ Rho\)是一个著名的大数质因数分解算法,它的实现基于一个神奇的算法:\(MillerRabin\)素数测试(关于\(MillerRabin\),可以参考这篇博客:初学MillerRabin素数测试). 期望下,\(Pollard\ Rho\)算法可以达到极快的复杂度. 核心思想 在\(ZJOI2019Day1\)讲课期间,它是被\(CQZ\)神仙作为随机算法内的一部分来进行介绍的. 由此可见,其核心思想便是随机二字. 操作流程 首先,我们先用\(MillerRabi…