Skip to content

Instantly share code, notes, and snippets.

@uhfx uhfx/sosu.c
Created Nov 8, 2013

Embed
What would you like to do?
【超低速】素数を求めるプログラム 範囲を指定できる
#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
You can’t perform that action at this time.