Created
May 1, 2016 06:04
-
-
Save ikr7/8036cafbd3c84c64b81be1ad4b5ce0a0 to your computer and use it in GitHub Desktop.
ポラード・ロー素因数分解アルゴリズム
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
'use strict'; | |
const xor64 = function (y) { | |
y = y >>> 0; | |
y = y ^ (y << 13); | |
y = y ^ (y >> 7); | |
y = y ^ (y << 17); | |
return y >>> 0; | |
}; | |
const GCD = function(m, n) { | |
while (n != 0) { | |
[m, n] = [n, m % n]; | |
} | |
return m; | |
} | |
const factorize = function (n) { | |
const f = function (seed) { | |
return xor64(seed) % n; | |
} | |
let x = 2; | |
let y = 2; | |
let d = 1; | |
while (d == 1) { | |
x = f(x); | |
y = f(f(y)); | |
d = GCD(Math.abs(x - y), n); | |
} | |
if (d == n) { | |
return false; | |
} | |
return d; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment