First of all if p and q are primes then p - q is even unless p=2 or q=2.

Next, there is no need to declare variable in Python.

Finally, there are optimized methods to access primes. Look
for prime_range, next_prime, Primes, etc

x = 3
while True:
    y = (10**18 // x).next_prime()
    ymax = (10**36 + x - 2) // x
    while y <= ymax:
        print("x = %d and y = %d" % (x, y))
        y = y.next_prime()
    x = x.next_prime()

Le 08/05/2020 à 23:00, u220e a écrit :


Hi. I'm trying to generate a list of pairs of primes (x,y) within a range
of values such that the digit length of their products is between 19 and
35. I've written a few different code variations that (unfortunately)
either (1) generate ALL the integer pairs (that equal 19, 20, 21, etc.) or
(2) never seem to halt.

I really want the iteration to be as follows: find the first pair that
equals 19, then locate the first pair that equals 20, and so on so until I
have one list of 17 pairs of primes---one pair for each digit length.
Here's what I have so far:

x=var('x')
y=var('y')
for x in sxrange (10**9,10**(36)):
    for y in sxrange (961748941,982451653):
       if x.is_prime()==1 and y.is_prime()==1:
             if (floor(log((x*y),10)+1)<=35)==1:
                print(x,y); print(floor(log((x*y),10)+1); break

Then I tried defining y=982451653 so I could use only one iterable using
the following code:

for x in sxrange (10**9,10**(36)):
    if x.is_prime()==1:
       if (floor(log((x*y),10)+1)>=19)==1:
          continue
       print(x,y); print(floor(log((x*y),10)+1); break

which returns only one value:

1000000007 982451653
18

Sorry for the n00b post. I've only been using Sage for three days.

Thanks,

David



--
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-support/6cf73850-ce04-3cbe-8748-ec41bdbe9b46%40gmail.com.

Reply via email to