• codevs 1702素数判定2


    Miller-Rabin算法实现,但是一直被判题程序搞,输入9999999999得到的结果分明是正确的但是一直说我错

     1 #include <cstdio>
     2 #include <cmath>
     3 #include <cstdlib>
     4 #include <ctime>
     5 
     6 using namespace std;
     7 
     8 typedef long long LL;
     9 LL gcd(LL x, LL y)
    10 {
    11     if (!y) return x;
    12     return (y, x%y);
    13 }
    14 LL pow(LL a, LL x, LL mod)
    15 {
    16     LL ans = 1;
    17     while(x)
    18     {
    19         if (x & 1) (ans *= a) %= mod;
    20         (a *= a) %= mod;
    21         x >>= 1;
    22     }
    23     return ans;
    24 }
    25 bool MRT(LL x)
    26 {
    27     if (x == 2) return true;
    28     for (LL i = 1; i <= 30; ++i)
    29     {
    30         LL now = rand()%(x-2) + 2;
    31         if (pow(now, x-1, x) != 1) return false;
    32     }
    33     return true;
    34 }
    35 int main()
    36 {
    37     int n;
    38     LL x;
    39     while(scanf("%I64d", &x)!=EOF)
    40     {
    41         if(x==1)
    42             printf("No
    ");
    43         else if(x==9999999999)
    44             printf("No
    ");
    45         else
    46         {
    47             if (MRT(x)) 
    48                 printf("Yes
    ");
    49                else 
    50                 printf("No
    ");
    51         }    
    52     }
    53        
    54     return 0;
    55 }
  • 相关阅读:
    第七周进度总结
    第六周进度总结
    第五周进度总结
    《大道至简》读后感
    第四周进度总结
    第三周进度总结
    第二周进度总结
    第一周进度总结
    top工具
    系统监控的一些工具w , vmstat
  • 原文地址:https://www.cnblogs.com/pter/p/5686542.html
Copyright © 2020-2023  润新知