tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 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