Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
29
Task/Prime-decomposition/E/prime-decomposition.e
Normal file
29
Task/Prime-decomposition/E/prime-decomposition.e
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
def primes := {
|
||||
var primesCache := [2]
|
||||
/** A collection of all prime numbers. */
|
||||
def primes {
|
||||
to iterate(f) {
|
||||
primesCache.iterate(f)
|
||||
for x in (int > primesCache.last()) {
|
||||
if (isPrime(x)) {
|
||||
f(primesCache.size(), x)
|
||||
primesCache with= x
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
def primeDecomposition(var x :(int > 0)) {
|
||||
var factors := []
|
||||
for p in primes {
|
||||
while (x % p <=> 0) {
|
||||
factors with= p
|
||||
x //= p
|
||||
}
|
||||
if (x <=> 1) {
|
||||
break
|
||||
}
|
||||
}
|
||||
return factors
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue