Last active
December 27, 2015 18:49
-
-
Save uhfx/7372689 to your computer and use it in GitHub Desktop.
【超高速】素数を求めるプログラム
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 <math.h> | |
int main(void) | |
{ | |
int i,j,k; | |
printf("2 "); //あらかじめ2を書いておくという手法 | |
for(i=10;i<=100;i+=2) //ここのiの値と10000の値をいじれば変わる | |
{ | |
k=0; | |
for(j=3;j<=sqrt(i);j+=2) | |
{ | |
if(i%j==0) | |
{ | |
k=1; | |
break; | |
} | |
} | |
if(k==0) printf("%d ",i); | |
} | |
printf("\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment