Skip to content

Instantly share code, notes, and snippets.

@uhfx
Last active December 27, 2015 18:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uhfx/7372689 to your computer and use it in GitHub Desktop.
Save uhfx/7372689 to your computer and use it in GitHub Desktop.
【超高速】素数を求めるプログラム
#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