June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -4,6 +4,7 @@ factors(N) ->
|
|||
factors(N,2,[]).
|
||||
|
||||
factors(1,_,Acc) -> Acc;
|
||||
factors(N,K,Acc) when N < K*K -> [N|Acc];
|
||||
factors(N,K,Acc) when N rem K == 0 ->
|
||||
factors(N div K,K, [K|Acc]);
|
||||
factors(N,K,Acc) ->
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ next
|
|||
|
||||
func isPrime num
|
||||
if (num <= 1) return 0 ok
|
||||
if (num % 2 = 0) return 0 ok
|
||||
if (num % 2 = 0) and num != 2 return 0 ok
|
||||
for i = 3 to floor(num / 2) -1 step 2
|
||||
if (num % i = 0) return 0 ok
|
||||
next
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
26
Task/Prime-decomposition/Stata/prime-decomposition.stata
Normal file
26
Task/Prime-decomposition/Stata/prime-decomposition.stata
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
function factor(n_) {
|
||||
n = n_
|
||||
a = J(0,2,.)
|
||||
if (n<2) {
|
||||
return(a)
|
||||
}
|
||||
else if (n<4) {
|
||||
return((n,1))
|
||||
}
|
||||
else {
|
||||
if (mod(n,2)==0) {
|
||||
for (i=0; mod(n,2)==0; i++) n = floor(n/2)
|
||||
a = a\(2,i)
|
||||
}
|
||||
|
||||
for (k=3; k*k<=n; k=k+2) {
|
||||
if (mod(n,k)==0) {
|
||||
for (i=0; mod(n,k)==0; i++) n = floor(n/k)
|
||||
a = a\(k,i)
|
||||
}
|
||||
}
|
||||
|
||||
if (n>1) a = a\(n,1)
|
||||
return(a)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue