Румен обнови решението на 15.10.2012 01:40 (преди около 12 години)
+class Integer
+ def prime_divisors
+ index = 2
+ number = self.abs
+ prime_devisors = []
+ while index <= number
+ if index.is_prime == true and number % index == 0
+ prime_devisors.push(index)
+ while number % index == 0
+ number /= index
+ end
+ end
+ index += 1
+ end
+ return prime_devisors
+ end
+
+ def is_prime
+ if self == 0 or self == 1
+ return false
+ end
+
+ index = 2
+ limit = Math.sqrt(self)
+ while index <= limit
+ if self % index == 0
+ return false
+ end
+ index += 1
+ end
+ return true
+ end
+end