June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,4 +1 @@
|
|||
require('ntheory')
|
||||
func prime_factors(n) {
|
||||
[%S<ntheory>.factor(n.to_s)]
|
||||
}
|
||||
say factor(536870911) #=> [233, 1103, 2089]
|
||||
|
|
|
|||
|
|
@ -1,18 +1,18 @@
|
|||
func prime_factors(n) {
|
||||
var p = 3;
|
||||
var out = [];
|
||||
return out if (n < 1);
|
||||
while (!(n & 1)) {
|
||||
n >>= 1;
|
||||
out << 2;
|
||||
}
|
||||
while ((n > 1) && (p*p <= n)) {
|
||||
while (n %% p) {
|
||||
n /= p;
|
||||
out << p;
|
||||
return [] if (n < 1)
|
||||
gather {
|
||||
while (!(n & 1)) {
|
||||
n >>= 1
|
||||
take(2)
|
||||
}
|
||||
p += 2;
|
||||
var p = 3
|
||||
while ((n > 1) && (p*p <= n)) {
|
||||
while (n %% p) {
|
||||
n //= p
|
||||
take(p)
|
||||
}
|
||||
p += 2
|
||||
}
|
||||
take(n) if (n > 1)
|
||||
}
|
||||
out << n if (n > 1);
|
||||
return out;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
say prime_factors(536870911);
|
||||
say prime_factors(536870911) #=> [233, 1103, 2089]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue