![]() |
![]() |
#1 |
Dec 2017
24×3×5 Posts |
![]() ![]() ![]() Code:
print('''SemiPrime Squared Prime test, Good for 5 digits and a little more on input!''') import time while True: start_time = time.time() p = int(input("Enter a prime number: ")) a = (((p*5)**2)-2) c = (((p*2)**2)+1) e = (((p*3)**2)-2) g = (((p*7)**2)-2) i = (((p*11)**2)-20) k = (((p*13)**2)-2) b = (p*5) d = (p*2) f = (p*3) h = (p*7) j = (p*11) l = (p*13) def isPrime(n) : # Corner cases if (n <= 1) : return False if (n <= 3) : return True # This is checked so that we can skip # middle five numbers in below loop if (n % 2 == 0 or n % 3 == 0) : return False i = 5 while(i * i <= n) : if (n % i == 0 or n % (i + 2) == 0) : return False i = i + 6 return True # Driver Program if (isPrime(a)) : print("|a| PRIME!",a,'|a|') else : print("|a| false",a,'|a|') if(isPrime(a)) : print("|a| PRIME!",a,'|a|') else : print("|a| false",a,'|a|') print(b,'|b|Semiprime product always of Five') if (isPrime(c)) : print("|c| PRIME!",c,'|c|') else : print("|c| false",c,'|c|') if(isPrime(c)) : print("|c| PRIME!",c,'|c|') else : print("|c| false",c,'|c|') print(d,'|d|Semiprime product always of Two') if (isPrime(e)) : print("|e| PRIME!",e,'|e|') else : print("|e| false",e,'|e|') if(isPrime(e)) : print("|e| PRIME!",e,'|e|') else : print("|e| false",e,'|e|') print(f,'|f|Semiprime product always of Three') if (isPrime(g)) : print("|g| PRIME!",g,'|g|') else : print("|g| false",g,'|g|') if(isPrime(g)) : print("|g| PRIME!",g,'|g|') else : print("|g| false",g,'|g|') print(h,'|h|Semiprime product always of Seven') if (isPrime(i)) : print("|i| PRIME!",i,'|i|') else : print("|i| false",i,'|i|') if(isPrime(i)) : print("|i| PRIME!",i,'|i|') else : print("|i| false",i,'|i|') print(j,'|j|Semiprime product always of Eleven') if (isPrime(k)) : print("|k| PRIME!",k,'|k|') else : print("|k| false",k,'|k|') if(isPrime(i)) : print("|k| PRIME!",k,'|k|') else : print("|k| false",k,'|k|') print(l,'|l|Semiprime product always of Thirteen') print('If Top Prime and Bottom false, than its Prime') e = int(time.time() - start_time) print('{:02d}:{:02d}:{:02d}'.format(e // 3600, (e % 3600 // 60), e % 60)) |
![]() |
![]() |
![]() |
#2 |
Undefined
"The unspeakable one"
Jun 2006
My evil lair
32×23×29 Posts |
![]() |
![]() |
![]() |
![]() |
#3 |
Dec 2017
24×3×5 Posts |
![]()
I just spotted something about this code.
Test any number one before a Twin Prime and the middle of twins and just one after the Twins and don't forget to test the Twins you often always get a Prime output and for some odd reason you don't the next prime produces a prime. |
![]() |
![]() |
![]() |
#4 | |
Jan 2012
Toronto, Canada
22·13 Posts |
![]() Quote:
So please do us all a favor and start educating yourself on some Python/coding/number theory basics before you make another thread on this forum. It'll make both your time and our time much more productive. |
|
![]() |
![]() |
![]() |
#5 |
Undefined
"The unspeakable one"
Jun 2006
My evil lair
177316 Posts |
![]()
I use tab characters. And my tab width is 8.
You can all hate me now, I don't care. Eight is the "correct" number, always. No need for all those wasteful space-space-space-space-space-space-space-space... things, using up the precious HDD capacity. Every byte matters. ![]() |
![]() |
![]() |
![]() |
#6 |
Jan 2012
Toronto, Canada
22·13 Posts |
![]()
That's actually a fair point, I think there is a heuristic for HTML pages where the ones that are written using tabs are 5-15% smaller and takes similarly less time to load. Or maybe you have a script with tens of thousands of lines where that might actually make a difference. I guess it isn't necessarily universal even among Python developers but it's in the official style guidelines (PEP 8).
Funnily I came upon this while doing a quick search... https://stackoverflow.blog/2017/06/1...oney-use-tabs/ |
![]() |
![]() |
![]() |
#7 | ||
Undefined
"The unspeakable one"
Jun 2006
My evil lair
32×23×29 Posts |
![]() Quote:
Quote:
|
||
![]() |
![]() |
![]() |
#8 | |
Dec 2017
24010 Posts |
![]() Quote:
![]() |
|
![]() |
![]() |
![]() |
#9 |
Aug 2006
3×1,987 Posts |
![]()
Let me break this down. You have 12 polynomials in p (let's suppose this is prime), six of which are quadratic and six of which are linear (constant multiples of p, in fact). But it's pretty obvious that a prime multiple of a prime will be semiprime, so that's true but trivial, and the quadratics will be less than 10% prime, less than 1% prime, less than 0.0000001% prime, ..., by sieve theory. (More can be said, conjecturally, about the relative density of the primes in each, though. Interested?)
Aside: Your code really needs work; you should have a function, say "test", where you can just call test(25*p**2 - 2, '|a|') and have the appropriate things done. Or better yet, scrap the need for the second argument entirely and apply the function directly to an array, like so: Code:
def test(n): # function definition goes here valuesToTest = [25*p**2-2, 4*p**2+1, 9*p**2-2, 49*p**2-2, 121*p**2-20, 169*p**2-2] results = map(test, valuesToTest) Code:
def test(n): # function definition goes here initialPrimes = [2, 3, 5, 7, 11, 13] offsets = [1, -2, -2, -2, -20, -2] valuesToTest = [ q*p for q in initialPrimes ] valuesToTest = [ k**2 for k in valuesToTest ] valuesToTest = [sum(x) for x in zip(valuesToTest, offsets)] results = map(test, valuesToTest) |
![]() |
![]() |
![]() |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Semiprime and Prime Generator | ONeil | ONeil | 2 | 2020-12-01 04:14 |
Semiprime and n-almost prime candidate for the k's with algebra for the Sierpinski/Riesel problem | sweety439 | sweety439 | 11 | 2020-09-23 01:42 |
...factorial(n) plus/minus 1 is semiprime | enzocreti | enzocreti | 3 | 2020-09-02 16:35 |
Semiprime counting | danaj | Computer Science & Computational Number Theory | 12 | 2018-10-14 03:16 |
Primorials squared primes? | siegert81 | Math | 6 | 2010-12-28 15:17 |