メイン factor.html   Last modified: Sep 01, 2009
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;CHARSET=EUC-JP">
<link rel="shortcut icon" href="../favicon.ico">
<title>JavaScript</title>

<script language="JavaScript">
<!--
var newline = (navigator.appVersion.lastIndexOf('Win') != -1) ? "\r\n" : "\n"

function prime(n)
{
  var i
  if (n % 2 == 0) {
    return 2
  }
  else if (n % 3 == 0) {
    return 3
  }
  
  for (i = 5; i*i <= n; i += 4) {
    if (n % i == 0) {
      return i
    }
    i += 2
    if (n % i == 0) {
      return i
    }
  }
  return n
}

function sep2(form)
{
  form.result.value += newline + "----------------------------------" + newline
}

function calc(form)
{
  var n, m, temp, sav, res = 1, i, first = 0
  if (isNaN(sav = n = parseFloat(form.data.value)) || n <= 0 || n != Math.ceil(n) || n > 1000000000000000) {
    form.result.value += "計算できません(入力数値が変です)"
    sep2(form)
    return
  }
  form.result.value += n + newline + "= "
  while (n > 1) {
    m = prime(n)
    temp = n
    i = 0
    while (temp % m == 0) {
      i++
      temp /= m
    }
    form.result.value += (first++ ? " * " : "") + m + (i > 1 ? ("^"+i) : "")
    res *= Math.pow(m, i)
    n /= Math.pow(m, i)
  }
  form.result.value += "  " + (sav == res ? "OK" : "NG !!!!")
  sep2(form)
}
//-->
</script>
</head>

<body bgcolor="#ffffff">
<font size="+2"><b>素因子分解</b></font> <a  href="src/factor.html"><img src="png/src.png" width=35 height=11 alt="src" align=top></a>     Last modified: Jun 01, 2006<hr noshade><p>
<font color="#ff0000" size="+2">以下のプログラムのサポートは終了しました。自己責任でお使い下さい。</font>

<form name=Result>
<script language="JavaScript">
<!--
//-->JavaScript がサポートされていないブラウザですか?
</script>
<input type="button" name="calcurate" value="計算開始" onClick="calc(this.form)">  
<input type="button" name="clear" value="入力欄クリア" onClick="this.form.data.value=''">  
<input type="button" name="clear" value="出力欄クリア" onClick="this.form.result.value=''">

<p>
15桁以内の整数値<input name="data" value=987654321 size=20><p>
出力欄<br><textarea name="result" ROWS=20 COLS=80></textarea>

</form>

<p><hr noshade>
<img src="../gra/button3.png" width=9 height=9 alt="・"> <A HREF="javascript:history.go(-1)">直前のページへ戻る</A>  <img src="../gra/button3.png" width=9 height=9 alt="・"> <a href="../mail.html">E-mail to Shigenobu AOKI</a>
<p><center><IMG SRC="../gra/ume5.png" width=121 height=37 ALT="Made with Macintosh"></center>
</body>
</html>


・ 直前のページへ戻る  ・ E-mail to Shigenobu AOKI

Made with Macintosh