Лазар обнови решението на 03.05.2012 00:22 (преди над 12 години)
+def primes():
+ yield 2;
+ numbers = 3;
+ while(True):
+ i = 2;
+ half_of_number = numbers / 2;
+ while(numbers % i != 0 and half_of_number > i):
+ i = i + 1;
+ if (numbers % i!= 0):
+ yield numbers;
+ numbers = numbers + 1;
+def semiprimes():
+ numbers = 4;
+ while(True):
+ divisor_one = primes();
+ divisor_one_value = next(divisor_one);
+ is_semiprime = False;
+ half_of_number = numbers / 2;
+ while(divisor_one_value <= half_of_number and not (is_semiprime)):
+ divisor_two = primes();
+ divisor_two_value = next(divisor_two);
+ while(divisor_one_value * divisor_two_value != numbers
+ and divisor_two_value <= half_of_number):
+ divisor_two_value = next(divisor_two);
+ if(divisor_one_value * divisor_two_value == numbers):
+ yield numbers;
+ is_semiprime = True;
+ divisor_one_value = next(divisor_one);
+ numbers = numbers + 1;