zoukankan      html  css  js  c++  java
  • Miller Rabin 总结

    费马小定理

    (a^pequiv apmod p)
    在 p 是质数时成立,考虑 rand 一个 a 来判定
    但是有一类数,满足费马小定理却又不是质数,如 561

    二次探测定理

    若 p 是质数且 (b^2equiv 1pmod p,0<x<p)
    原式减一可得(b^2-1equiv 0pmod p),平方差((b+1)(b-1)equiv 0pmod p)
    故 p 一定可以被 (b+1) 和 (b-1) 其中至少一个整除,所以 (b=1,p-1) 。若 b=1 ,可以继续探测

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long LL;
    typedef unsigned long long uLL;
    typedef long double LD;
    inline LL Abs(LL x) { return x<0?-x:x; }
    inline LL Mul(uLL x,uLL y,LL p) { return (x*y-(uLL)((LD)x/p*y)*p+p)%p; }
    inline LL Pow(LL x,LL y,LL p){
    	register LL res=1;
    	for(;y;y>>=1,x=Mul(x,x,p))
    	if(y&1)res=Mul(res,x,p);
    	return res;
    }
    inline bool Mr(LL n,LL p) {
        if(Pow(p,n-1,n)!=1)return 0;
        register LL q=n-1,o;
        while(!(q&1)) {
            q>>=1,o=Pow(p,q,n);
            if(o!=1 && o!=n-1)return 0;
            if(o==n-1)return 1;
        }
        return 1;
    }
    inline bool Prime(LL n) {
        if(n<2)return false;
        if(n==2||n==3||n==5||n==7||n==43)return true;
        return Mr(n,2)&&Mr(n,3)&&Mr(n,5)&&Mr(n,7)&&Mr(n,43);
    }
    int main() {
        srand(20080816);
        return 0;
    }
    
  • 相关阅读:
    数据库练习
    pymysql
    数据库索引
    数据库查询
    数据库操作
    数据库建表
    数据库初识
    shell 编程
    Struts2与SpringMVC
    SpringAOP
  • 原文地址:https://www.cnblogs.com/KonjakLAF/p/14332068.html
Copyright © 2011-2022 走看看