Finding efficiently primes, whose begining numbers are also primes. See the thread http://www.daniweb.com/software-development/cpp/threads/425821/prime-number-c in C++ forum for discussion on topic.

Member Avatar
+1 forum 0

I made a program to find primes, but it can't find any prime less that 7(e.g. 2, 3, 5) any ideas? [CODE]import math from math import sqrt x = 1 y = raw_input("What number do you wish to find all the primes below? ") y = int(y) while x < y: a = 2 while a < x: if x % a == 0: a = x elif a == x-1: if y % a == 0: a = x else: print x a = x else: a = a+1 x = x+1[/CODE]

Member Avatar
Member Avatar
+0 forum 4

This I did also after 'spying' discussions in other forum. Of course you would use sieve prime generation for bigger numbers, but I proved other simple way for a change. Slightly more advanced primes list generator would use primes % 6 in (1,5) property: [CODE]def primes(n): """ primitive non-sieve prime finder """ p = [2, 3] candidate, step = 5, 2 while candidate <= n: if all(candidate % pr for pr in p): p.append(candidate) candidate += step # consider only number % 6 in (1,5) ie 6*n +- 1 step = 2 if step == 4 else 4 return p …

Member Avatar
Member Avatar
+0 forum 1

Hi all, I wrote code to list primes that are in a given "radius" of an even number. For example, 6 - 1 = 5 and 6 + 1 = 7, 14 - 3 = 11 and 14 + 3 = 17, etc. I used Euler's sieve to obtain the primes. Can the following code be further optimized? If so, how? I eventually want to be able to plot the primes for a given even number. All help is appreciated, thanks! Here's the code: [CODE]n = int(raw_input("Num: ")) s = range(3, n+1, 2) i = 1 a = len(s) - …

Member Avatar
+0 forum 0

The End.