Re: right prime numbers



#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.

.



Relevant Pages

  • Re: multiplying two numbers and giving the sqare root
    ... Here is the source for the square root: ... > using namespace std; ... > int main ... > here is the source for multiplying the two integers: ...
    (alt.comp.lang.learn.c-cpp)
  • Re: right prime numbers
    ... and print one line of text that indicates if the int. ... i am in beginning programing so complex is complicated. ... It does not use the square root function, ...
    (comp.lang.c)
  • Re: how can I return nothing?
    ... /* This program implements a blindingly fast Oalgorithm ... using an elegant recursive method. ... int _ ...
    (comp.lang.c)
  • Re: flowchart
    ... /* This program implements a blindingly fast Oalgorithm ... using an elegant recursive method. ... int _ ...
    (comp.lang.c)