answersLogoWhite

0


Best Answer

...

for(m = 6; m < n; m += 6){
if(isPrime(m - 1) && isPrime(m + 1)){
printf("(%i, %i)\n", m - 1, m + 1);

}

}

...

/*
a quick'n'dirty algorithm for checking if a number is prime or composite. Returns 1 if the number is prime, 0 otherwise. Takes advantages of the following facts:

  1. with the exception of 2 and 3, all prime numbers are 1 away from a multiple of 6
  2. you don't need to check for divisibility by composite numbers, only primes
  3. you only need to check for divisibility up to the square root of the number in question
*/

int isprime(unsigned int val){
int n, returnval = 1;
if(val == 1) return 0;
if(!(val % 2 && val % 3)) return 0;
if(val % 6 != 1 && val % 6 != 5) return 0;

for(n = 6; (n - 1) * (n - 1) <= val; n++){
if(!(val % (n - 1) && val % (n + 1)){
returnval = 0;
break;

}

}
return returnval;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is an algorithm to find all primes below a given number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you find twin primes of number?

To find twin primes of a given number, iterate through the numbers starting from the given number, and for each number, check if both the number and the number+2 are prime. If they are, then they form a pair of twin primes with the given number.


What is the factor that makes these prime numbers so important for the rsa?

It is very difficult to factorise a number that is the product of two very large primes but, given one of these primes, it is very easy to verify the result and to find the other prime.It is very difficult to factorise a number that is the product of two very large primes but, given one of these primes, it is very easy to verify the result and to find the other prime.It is very difficult to factorise a number that is the product of two very large primes but, given one of these primes, it is very easy to verify the result and to find the other prime.It is very difficult to factorise a number that is the product of two very large primes but, given one of these primes, it is very easy to verify the result and to find the other prime.


Which prime numbers are greater than 100?

There are an infinite number of primes greater than any number given.


What is an iterative procedure which determines all the primes less than a given number?

the Sieve of Eratosthenes


Is 167 a composite number?

== == No, it's a prime - because none of the primes less than 13 will divide the given number.


Is 52563744 divisible by 24?

Sol: 24 = 3 x 8, where 3 and 8 are co-primes. The sum of the digits in the given number is 36, which is divisible by 3. So, the given number is divisible by 3. The number formed by the last 3 digits of the given number is 744, which is divisible by 8. So, the given number is divisible by 8. Thus, the given number is divisible by both 3 and 8, where 3 and 8 are co-primes. So, it is divisible by 3 x 8, i.e., 24.


What is complsexity of an algorithm?

Complexity of an algorithm is a measure of how long an algorithm would take to complete given


A Write the algorithm to concatenate two given strings?

a write the algorithm to concatenate two given string


Are there more primes or composites?

In any large range of numbers, more so the higher and larger the range is, there will be more composites than primes. It is far more likely that a given number will be divisible by some number less than the number itself, the higher you go.


Are 29 and 31 twin primes?

Yes, 29 and 31 are twin primes.Explanation:A pair of primes that differ by 2 are called twin primes.29 and 31 both are primes and their difference is 31-29 = 2. So, the given pair of primes is twin primes.


Prove that if every even natural number greater than 2 is the sum of two primes then every odd natural number greater than 5 is the sum of three primes?

Given an arbitrary odd natural number greater than five, x, let y = x - 3, then y is an even number greater than 2. By assumption we have that y is the sum of two primes, say y1 and y2, but then x = y1 + y2 + 3 (which is the sum of three primes).


Write an algorithm to check whether the given number is odd or even?

Type your answer here... i think we should first enter 1 number then check it