tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
39
Task/Prime-decomposition/JavaScript/prime-decomposition-1.js
Normal file
39
Task/Prime-decomposition/JavaScript/prime-decomposition-1.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
function run_factorize(input, output) {
|
||||
var n = new BigInteger(input.value, 10);
|
||||
var TWO = new BigInteger("2", 10);
|
||||
var divisor = new BigInteger("3", 10);
|
||||
var prod = false;
|
||||
|
||||
if (n.compareTo(TWO) < 0)
|
||||
return;
|
||||
|
||||
output.value = "";
|
||||
|
||||
while (true) {
|
||||
var qr = n.divideAndRemainder(TWO);
|
||||
if (qr[1].equals(BigInteger.ZERO)) {
|
||||
if (prod)
|
||||
output.value += "*";
|
||||
else
|
||||
prod = true;
|
||||
output.value += "2";
|
||||
n = qr[0];
|
||||
}
|
||||
else
|
||||
break;
|
||||
}
|
||||
|
||||
while (!n.equals(BigInteger.ONE)) {
|
||||
var qr = n.divideAndRemainder(divisor);
|
||||
if (qr[1].equals(BigInteger.ZERO)) {
|
||||
if (prod)
|
||||
output.value += "*";
|
||||
else
|
||||
prod = true;
|
||||
output.value += divisor;
|
||||
n = qr[0];
|
||||
}
|
||||
else
|
||||
divisor = divisor.add(TWO);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue