fork download
  1. def factorize = { long target ->
  2.  
  3. if (target == 1) return [1L]
  4.  
  5. if (target < 4) return [1L, target]
  6.  
  7. def targetSqrt = Math.sqrt(target)
  8. def lowfactors = (2L..targetSqrt).findAll { (target % it) == 0 }
  9. if (lowfactors == []) return [1L, target]
  10. def nhalf = lowfactors.size() - ((lowfactors[-1]**2 == target) ? 1 : 0)
  11.  
  12. [1] + lowfactors + (0..<nhalf).collect { target.intdiv(lowfactors[it]) }.reverse() + [target]
  13. }
  14.  
  15. def decomposePrimes = { target ->
  16. def factors = factorize(target) - [1]
  17. def primeFactors = []
  18. factors.eachWithIndex { f, i ->
  19. if (i==0 || factors[0..<i].every {f % it != 0}) {
  20. primeFactors << f
  21. def pfPower = f*f
  22. while (target % pfPower == 0) {
  23. primeFactors << f
  24. pfPower *= f
  25. }
  26. }
  27. }
  28. primeFactors
  29. }
  30.  
Success #stdin #stdout 0.86s 217088KB
stdin
Standard input is empty
stdout
Standard output is empty