找回密码
 欢迎注册
查看: 12062|回复: 6

[原创] 基于2^64以下的以2为底的伪素数的数据分析

[复制链接]
发表于 2016-1-11 15:14:14 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?欢迎注册

×
在下面网站找到了所有的低于2^64的以2为底伪素数PSP(2)的表
http://www.cecm.sfu.ca/Pseudoprimes/index-2-to-64.html

下载后进行了一些分析,详细结果,后面列出来
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2016-1-11 15:27:02 | 显示全部楼层
下载的是第3项,包含Carmichael数跟强伪素数分类,和因子分解的部分
首先是统计信息,共118968379个, 其中强伪素数31894015个; Carmichael数4279356个, 既是Carmichael数又是强伪素数的32596个
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2016-1-12 15:34:27 | 显示全部楼层
可以给gxqcn用
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2016-1-12 16:53:35 | 显示全部楼层
对这些数据进行了强伪素数检测,首先过滤出31894016组base 2的强伪素数,
再进行base 3, 5, 7的单独或者组合测试,结果如下,数字代表通过测试的强伪素数数量
Total: 31894016
   base 2, 3 -- 1501720
       base 2, 3, 5 -- 131157
           base 2, 3, 5, 7 -- 16826
       base 2, 3, 7 -- 171359
   base 2, 5 -- 1330740
       base 2, 5, 7 -- 126999
   base 2, 7 -- 1363175
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2016-1-12 16:55:27 | 显示全部楼层
过滤出强伪素数的代码
  1. #include <stdio.h>
  2. #include <stdlib.h>


  3. int main( void )
  4. {
  5.   FILE * psp2, *S64;
  6.   char buf[256];
  7.   int i=0;
  8.   if ((psp2=fopen("psp2.txt", "rt"))!=NULL)
  9.     if ((S64 = fopen("S64.txt", "wt"))!=NULL)
  10.     {
  11.       while (!feof(psp2))
  12.       {
  13.         fgets(buf, 256, psp2);
  14.         if (buf[1] == 'S')
  15.         {
  16.           fputs(buf, S64);
  17.           i ++;
  18.           if (i >= 1000)
  19.           {
  20.             i=0;
  21.             fflush(S64);
  22.           }
  23.         }
  24.       }
  25.     }
  26.   fclose(psp2);
  27.   fclose(S64);
  28. }
复制代码
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
 楼主| 发表于 2016-1-12 16:59:48 | 显示全部楼层
基于linux 64位汇编的测试代码
m64.s
  1. .data
  2. .text
  3. .global powMod, oddDivisorOf, strongPseudoPrimeTest

  4. powMod:
  5. #return rax = rdi ^ rsi mod rdx
  6. #unsigned long long powMod(unsigned long long n, unsigned long long p, unsigned long long m)
  7.         movq %rdi, %rax
  8.         movq %rdx, %rcx
  9.         movq $1, %r8
  10.         movq $1, %r9
  11. powModStart:
  12.         cmpq %r9, %rsi
  13.         jbe  powModExit
  14.         testq %r9, %rsi
  15.         je powModSquare
  16.         movq %rax, %rdi
  17.         mulq %r8
  18.         divq %rcx
  19.         movq %rdi, %rax
  20.         movq %rdx, %r8
  21. powModSquare:
  22.         mulq %rax
  23.         divq %rcx
  24.         movq %rdx, %rax
  25.         shrq $1, %rsi
  26.         jmp powModStart
  27. powModExit:
  28.         mulq %r8
  29.         divq %rcx
  30.         movq %rdx, %rax
  31.         ret

  32. oddDivisorOf:
  33. #rdi = 2^n * rax, rax is odd number
  34.         bsf %rdi, %rcx
  35.         movq %rdi, %rax
  36.         shrq %cl, %rax
  37.         testq $1, %rdi
  38.         cmovne %rdi, %rax
  39.         ret

  40. strongPseudoPrimeTest:
  41. #retrun rdi base rsi Strong PseudoPrime Test
  42.         movl $0, %eax
  43.         testq $1, %rdi
  44.         je strongPseudoPrimeTestExit
  45.         movq %rdi, %xmm0
  46.         subq $1, %rdi
  47.         bsf %rdi, %rcx
  48.         movd %ecx, %xmm1
  49.         shrq %cl, %rdi
  50.         xchg %rsi, %rdi
  51.         movq %xmm0, %rdx
  52.         call powMod
  53.         cmpq $1, %rax
  54.         je strongPseudoPrimeTestExit
  55.         movd %xmm1, %ecx
  56.         movq %xmm0, %r8
  57.         movq %xmm0, %r9
  58.         subq $1, %r8
  59.         cmpq %r8, %rax
  60.         je strongPseudoPrimeTestCheck
  61.         subl $1, %ecx
  62.         cmpl $0, %ecx
  63.         je strongPseudoPrimeTestCheck
  64. strongPseudoPrimeTestLoop:
  65.         mulq %rax
  66.         divq %r9
  67.         movq %rdx, %rax
  68.         cmpq %r8, %rax
  69.         je strongPseudoPrimeTestCheck
  70.         subl $1, %ecx
  71.         jne strongPseudoPrimeTestLoop
  72. strongPseudoPrimeTestCheck:
  73.         movq $1, %rcx
  74.         movq $0, %rdx
  75.         cmpq %r8, %rax
  76.         cmove %rcx, %rax
  77.         cmovne %rdx, %rax
  78. strongPseudoPrimeTestExit:
  79.         ret
复制代码


S2.c
  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. extern int strongPseudoPrimeTest(unsigned long long n, unsigned long long base);

  4. int main( void )
  5. {
  6.   FILE *S64, *S23, *S25, *S27, *S235, *S237, *S257, *S2357;
  7.   char buf[256], C;
  8.   int C64=0, C23=0, C25=0, C27=0, C235=0, C237=0, C257=0, C2357=0;
  9.   int P3, P5, P7;
  10.   unsigned long long p;
  11.   if ((S64=fopen("S64.txt", "rt"))!=NULL)
  12.   {
  13.     if ((S23 = fopen("S23.txt", "wt"))!=NULL)
  14.     if ((S25 = fopen("S25.txt", "wt"))!=NULL)
  15.     if ((S27 = fopen("S27.txt", "wt"))!=NULL)
  16.     if ((S235 = fopen("S235.txt", "wt"))!=NULL)
  17.     if ((S237 = fopen("S237.txt", "wt"))!=NULL)
  18.     if ((S257 = fopen("S257.txt", "wt"))!=NULL)
  19.     if ((S2357 = fopen("S2357.txt", "wt"))!=NULL)
  20.     {
  21.       while (!feof(S64))
  22.       {
  23.         fgets(buf, 256, S64);
  24.         C64++;
  25.         buf[1]=' ';
  26.         sscanf(buf+2, "%llu", &p);
  27.         P3=strongPseudoPrimeTest(p, 3);
  28.         P5=strongPseudoPrimeTest(p, 5);
  29.         P7=strongPseudoPrimeTest(p, 7);
  30.         if (P3)
  31.         {
  32.                 C23++;
  33.                 fputs(buf, S23);

  34.                 if (P5)
  35.                 {
  36.                         C235++;
  37.                         fputs(buf, S235);

  38.                         if (P7)
  39.                         {
  40.                                 C2357++;
  41.                                 fputs(buf, S2357);
  42.                         }
  43.                 }

  44.                 if (P7)
  45.                 {
  46.                         C237++;
  47.                         fputs(buf, S237);
  48.                 }
  49.         }

  50.         if (P5)
  51.         {
  52.                 C25++;
  53.                 fputs(buf, S25);

  54.                 if (P7)
  55.                 {
  56.                         C257++;
  57.                         fputs(buf, S257);
  58.                 }
  59.         }

  60.         if (P7)
  61.         {
  62.                 C27++;
  63.                 fputs(buf, S27);
  64.         }

  65.       }
  66.     }
  67.   }
  68.   fclose(S64);
  69.   fclose(S23);
  70.   fclose(S25);
  71.   fclose(S27);
  72.   fclose(S235);
  73.   fclose(S237);
  74.   fclose(S257);
  75.   fclose(S2357);
  76.   printf("Total: %llu\n", C64);
  77.   printf("   base 2, 3 -- %llu\n", C23);
  78.   printf("       base 2, 3, 5 -- %llu\n", C235);
  79.   printf("           base 2, 3, 5, 7 -- %llu\n", C2357);
  80.   printf("       base 2, 3, 7 -- %llu\n", C237);
  81.   printf("   base 2, 5 -- %llu\n", C25);
  82.   printf("       base 2, 5, 7 -- %llu\n", C257);
  83.   printf("   base 2, 7 -- %llu\n", C27);
  84.   return 0;
  85. }
复制代码


linux下编译命令
gcc -O3 -o S2 S2.c m64.s

粗略的算了下,每次测试大概7100时钟左右,不知道是否存在优化的可能
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2019-2-25 08:34:21 | 显示全部楼层
无心人 发表于 2016-1-12 16:53
对这些数据进行了强伪素数检测,首先过滤出31894016组base 2的强伪素数,
再进行base 3, 5, 7的单独或者组 ...

你真棒,那么大的数据都能搞得动!
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-4-27 04:15 , Processed in 0.068621 second(s), 16 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表