Created
November 8, 2013 15:30
-
-
Save uhfx/7372662 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> | |
int main(void) | |
{ | |
int m, n, is_prime, i, num = 0; | |
scanf("%d", &m); | |
scanf("%d", &n); | |
for( num = m; num < n+1 ; num++ ){ | |
is_prime = 1; /* num が変わるごとに再初期化しましょう */ | |
for( i = 2; i< num+1 ; i++){ | |
if( (num % i) == 0 ){ | |
is_prime++; | |
} | |
} /* 素数判定はループの外で行いましょう */ | |
if( is_prime == 2 ) | |
printf("%d\n", num); /* & つけちゃダメです */ | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment