素数の新定理発見 極端な偏りなく分布 米英数学者「夢のような成果」 ― スポニチ Sponichi Annex 社会
Created
February 26, 2014 06:28
-
-
Save mikecat/9224574 to your computer and use it in GitHub Desktop.
どの区間[n,n+600]にも必ず素数が2個含まれるというわけではない(出力例はgmp-5.1.3を使用)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
YUKI.N>prime600 1024 10 | |
# seed = 1393395669 | |
# bits = 1024 | |
60 | |
1488 | |
628 | |
1170 | |
1900 | |
120 | |
246 | |
1842 | |
162 | |
1314 | |
# max diff = 1900 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <time.h> | |
#include <gmp.h> | |
int main(int argc,char* argv[]) { | |
int bits=1024; | |
int iteration=100; | |
int i; | |
unsigned long int seed=0; | |
mpz_t now,next,diff,max; | |
gmp_randstate_t rns; | |
FILE* fp; | |
if((fp=fopen("/dev/urandom","rb"))!=NULL) { | |
if(fread((void*)&seed,sizeof(unsigned long int),1,fp)==0) { | |
seed=(unsigned long int)time(NULL); | |
} | |
} else { | |
seed=(unsigned long int)time(NULL); | |
} | |
if(argc>=2)sscanf(argv[1],"%d",&bits); | |
if(argc>=3)sscanf(argv[2],"%d",&iteration); | |
gmp_randinit_default(rns); | |
gmp_randseed_ui(rns,seed); | |
mpz_inits(now,next,diff,max,NULL); | |
mpz_set_ui(max,0); | |
printf("# seed = %lu\n",seed); | |
printf("# bits = %d\n",bits); | |
putchar('\n'); | |
for(i=0;i<iteration;i++) { | |
mpz_urandomb(now,rns,bits); | |
mpz_nextprime(now,now); | |
mpz_nextprime(next,now); | |
mpz_sub(diff,next,now); | |
mpz_out_str(stdout,10,diff); | |
putchar('\n'); | |
if(mpz_cmp(diff,max)>0) { | |
mpz_set(max,diff); | |
} | |
} | |
fputs("\n# max diff = ",stdout); | |
mpz_out_str(stdout,10,max); | |
putchar('\n'); | |
gmp_randclear(rns); | |
mpz_clears(now,next,diff,max,NULL); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment