Last active
December 12, 2015 07:58
-
-
Save defvol/4740383 to your computer and use it in GitHub Desktop.
438 bytes to print the biggest prime number (a cleaner version)
This file contains hidden or 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
| // All credits go to Fabrice Bellard http://bellard.org/mersenne.html | |
| #include <stdio.h> | |
| int m=167772161,N=1,t[1<<25]={2},a,*p,i,e=34893349,s,c,U=1; | |
| g(d,h) { | |
| for(i=s;i<1<<24;i*=2)d=d*1LL*d%m; | |
| for(p=t;p<t+N;p+=s) | |
| for(i=s,c=1;i;i--) | |
| a=p[s]*(h?c:1LL)%m,p[s]=(m+*p-a)*(h?1LL:c)%m,a+=*p,*p++=a%m,c=c*1LL*d%m; | |
| } | |
| main() { | |
| while(e/=2) { | |
| N*=2;U=U*1LL*(m+1)/2%m; | |
| for (s=N;s/=2;)g(17,0); | |
| for(p=t;p<t+N;p++)*p=*p*1LL**p%m*U%m; | |
| for(s=1;s<N;s*=2) | |
| g(29606852,1); | |
| for(a=0,p=t;p<t+N;) | |
| a+=*p<<(e&1),*p++=a%10,a/=10; | |
| } | |
| while(!*--p); | |
| for(t[0]--;p>=t;)putchar(48+*p--); | |
| } | |
| /* | |
| Tested on a MacBook Air (1.8 GHz Intel Core i5) | |
| Results: http://dl.dropbox.com/u/47709433/biggest-prime-number | |
| */ |
el buen fabrice bellard lo vuelve a hacer
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
After 01:25.8 minutes I got
http://dl.dropbox.com/u/47709433/biggest-prime-number