Skip to content

Instantly share code, notes, and snippets.

@megascus
Created August 12, 2012 01:31
Show Gist options
  • Save megascus/3328684 to your computer and use it in GitHub Desktop.
Save megascus/3328684 to your computer and use it in GitHub Desktop.
素数の時にJoJo(Java)
/**
*
* @author megascus
*/
public class JoJo {
public static void main(String[] args) {
for (int i = 1; i <= 100; i++) {
System.out.println(isPrime(i) ? "JoJo" : i);
}
}
static boolean isPrime(int p) {
if (p < 2) {
return false;
}
if (p == 2) {
return true;
}
if (p % 2 == 0) {
return false;
}
for (int i = 3; i * i <= p; i = i + 2) {
if (p % i == 0) {
return false;
}
}
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment