Skip to content

Instantly share code, notes, and snippets.

@LightBells
Last active May 20, 2019 10:48
Show Gist options
  • Save LightBells/8658e31629e8f8d9fa940eb41336c391 to your computer and use it in GitHub Desktop.
Save LightBells/8658e31629e8f8d9fa940eb41336c391 to your computer and use it in GitHub Desktop.
PrimeJudgement
#include <stdio.h>
#define FALSE 0
#define TRUE 1
int main(){
bool isNotPrime = FALSE;
for (int i=2 ; i <= 1000 ; i++) {
for (int j=2 ; j < i ; j++){
if ( i%j == 0 ){
isNotPrime = TRUE;
}
}
if (isNotPrime == FALSE){
printf("%4d\n", i);
}
isNotPrime = FALSE;
}
return 0;
}
@LightBells
Copy link
Author

LightBells commented May 20, 2019

判定用変数はisNotPrime
ある数n∈Nが任意のx {x | x∈N, 1<x<n}で割ることができない数であることが素数の条件だから、それをチェックしてる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment