Re: right prime numbers
- From: "Don" <dondodson@xxxxxxxxx>
- Date: 28 Nov 2006 10:33:14 -0800
#include <stdio.h>
/* This program implements a blindingly fast O(n^n) algorithm to
find right prime numbers, using an elegant recursive method.
It does not use the square root function, which is very slow. */
int _(int n, int m, int d)
{
int r = m != n;
for(int i=0; d && (i<n); i++)
r *= _(n,(m<=n)?i*m:0,d-1)|!_(i,1,i);
return r;
}
/*------------------------------------------
Print right primes up to the requested value
--------------------------------------------*/
int main(int argc, char* argv[])
{
for(int n = 2; n < 100000; n++)
printf("%d is%s right prime\n",n, _(n,1,n)?"" : " not");
return 0;
}
johnmsimon@xxxxxxxxx wrote:
i need to develop a code that finds a prime right number between 2 and
100000. and print one line of text that indicates if the int. is right
prime. i am in beginning programing so complex is complicated. we are
on a functions chapter. i am usung the square root to find the prime.
so far i have accomplished this but i cant fgure how to divide this by
ten so i can find the right prime. i am using c.
i know this can not be as complicated as i have made it.
.
- Follow-Ups:
- Re: right prime numbers
- From: Keith Thompson
- Re: right prime numbers
- References:
- right prime numbers
- From: johnmsimon
- right prime numbers
- Prev by Date: Re: Please Help ----------Free Downloadable Ebooks for C & C++ Language needed
- Next by Date: Re: Macros
- Previous by thread: Re: right prime numbers
- Next by thread: Re: right prime numbers
- Index(es):
Relevant Pages
|
|