zoukankan      html  css  js  c++  java
  • 素数判定

    个人觉得这篇博客总结的很好:http://blog.csdn.net/arvonzhang/article/details/8564836

    再添加一个可以直接复制粘贴的模板:

    ll POW_MOD(ll aa,ll ii,ll nn)
    {
      if(ii==0)
        return 1%nn;
      ll temp=POW_MOD(aa,ii>>1,nn);
      temp=temp*temp%nn;
      if(ii&1)
        temp=temp*aa%nn;
      return temp;
    }
    bool TEST (ll n,ll a,ll d)
    {
      if(n==2)
        return true;
      if(n==a)
        return true;
      if((n&1)==0)
        return false;
      while(!(d&1))
        d=d>>1;
      ll t=POW_MOD(a,d,n);
      while((d!=n-1)&&(t!=1)&&(t!=n-1))
      {
        t=(ll)t*t%n;
        d=d<<1;
      }
      return (t==n-1||(d&1)==1);
    }
    bool ISPRIME(ll n)
    {
      if(n<2)
        return false;
      ll a[]= {2,3,5,7,61};
      for(int i=0; i<=4; i++)
        if(!TEST(n,a[i],n-1))
          return false;
      return true;
    }
    View Code
  • 相关阅读:
    python 项目实例
    flash教程
    flask request
    systemd-unit
    kubernets HA集群手动部署
    zookeeper(1)-简单介绍
    apache与nginx原理
    技术文章整理
    CMS垃圾回收器
    Zookeeper
  • 原文地址:https://www.cnblogs.com/acm-jing/p/4814017.html
Copyright © 2011-2022 走看看