Created
September 11, 2012 14:35
-
-
Save kazua/3699170 to your computer and use it in GitHub Desktop.
JOJO
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
<html> | |
<head> | |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> | |
<meta http-equiv="Content-Script-Type" content="text/javascript"> | |
<title>素数の時だけJOJO!</title> | |
<script type="text/javascript"> | |
for(var i = 1; i <= 100; i++){ | |
var c = 0;//カウンタを初期化 | |
var p = 1;//素数フラグを立てる | |
for(var j = 1; j <= i; j++){ | |
if(i % j == 0) c++;//割りきれればカウントアップ | |
if(c == 2 && j != i){//自分と同値になる前に二度割りきれれば素数ではない | |
p = 0;//素数フラグをおろす | |
break; | |
} | |
} | |
if(i != 1 && p == 1){//1以外で素数フラグが立っていれば素数 | |
document.write("JOJO!<br>"); | |
}else{ | |
document.write(i+"<br>"); | |
} | |
} | |
</script> | |
</head> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment