[algogeeks] Re: Prime numbers

2011-08-17 Thread Don
_(n,1,n,0) is true if n is prime. I set out to create an O(n^n) algorithm. It essentially computes the product of every possible set of n integers in the range (1..n-1). If any of those products equal n, the number is composite. You will notice that the program does not use the * operator to perfo

Re: [algogeeks] Re: Prime numbers

2011-08-17 Thread Sanjay Rajpal
@Don : can you plz explain it ? Sanjay Kumar B.Tech Final Year Department of Computer Engineering National Institute of Technology Kurukshetra Kurukshetra - 136119 Haryana, India -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to thi

[algogeeks] Re: Prime numbers

2011-08-17 Thread Don
I wrote it. Can you figure out how it works? Don On Aug 17, 1:25 am, Nitin Nizhawan wrote: > Hi Dod, > >   Could you pls expalin what this algorithm is doing and from where you got > it. > > Thanks > Nitin > > On Wed, Aug 17, 2011 at 2:56 AM, Don wrote: > > I wrote a program to print prime numbe

Re: [algogeeks] Re: Prime Numbers

2011-07-24 Thread Ankur Garg
Do take a look at this also http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes#cite_note-7 Source code to list all prime numbers till number n #include #include #define bool int using namespace std; int main(){ int n; cin>>n; int i,j; bool primeValues[1000]={0}; for(i=4;i<=n;i=i+2

[algogeeks] Re: Prime Numbers

2011-07-23 Thread frank
thanq u very much On Jul 23, 10:13 pm, arun kumar wrote: > hope this link will help > youhttp://www.topcoder.com/tc?module=Static&d1=tutorials&d2=primalityTes... > > > > > > > > On Sat, Jul 23, 2011 at 10:39 PM, frank wrote: > > what is the efficient algorith to find the prime numbers or to ch

[algogeeks] Re: Prime Numbers

2011-01-29 Thread sankalp srivastava
Okay I got it myself @OP This can be done in O(n*k*logn) where k is of order 10^3 at the very max , when u need a prime like 1 trillion On Jan 28, 6:44 pm, sankalp srivastava wrote: > Correct me if I'm wrong , but according to you , will this be the > approach ? > > boolean array[10]; > int

[algogeeks] Re: Prime Numbers

2011-01-28 Thread sankalp srivastava
Correct me if I'm wrong , but according to you , will this be the approach ? boolean array[10]; int primes[100]; void seive() { int index=0; for(int i=2;i*i<10;i++) { if(isprime[i]) { primes[index++]=i; for(int j=i*2;j<100;j+=i)

[algogeeks] Re: Prime Numbers

2011-01-27 Thread alexsolo
#include #include #include #define MAX 15485863 #define LMT 100 unsigned flag[MAX>>6]; #define ifc(n) (flag[n>>6]&(1<<((n>>1)&31))) #define isc(n) (flag[n>>6]|=(1<<((n>>1)&31))) void sieve() { unsigned i, j, k; for(i=3; i>6); } -- You received this message because you are subsc

[algogeeks] Re: Prime Numbers

2011-01-26 Thread juver++
@above One million is 10^6. Problem wants 1 million of prime numbers. Not the prime numbers in range 1..1000. So, you should use two sieves. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@g

Re: [algogeeks] Re: Prime Numbers

2011-01-26 Thread siddharth srivastava
@rahul, juver++,sankalp Though this can be solved using incrementing the range in sieve. But due to this incremental approach how much the efficiency can be improved, any guesses :) -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to

[algogeeks] Re: Prime Numbers

2011-01-26 Thread sankalp srivastava
Use a seive . it's complexity is O(nlog n) 1 million is 1*10^7 , this will run within time limit ... assuming u optimize ur code enough !! On Jan 26, 5:48 pm, juver++ wrote: > Generate primes numbers for the range 1..10^7 using sieve. > Than apply sieve bigger range using these prime numbers. --

Re: [algogeeks] Re: Prime Numbers

2011-01-26 Thread juver++
Generate primes numbers for the range 1..10^7 using sieve. Than apply sieve bigger range using these prime numbers. -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@googlegroups.com. To unsubscrib

Re: [algogeeks] Re: Prime Numbers

2011-01-26 Thread rahul rai
I think one can use an elimination method . List out all the numbers . Keep on eliminating the multiples of 2{excluding 2} , then multiples of 3 , then multiples of 5 , then 7 , the denseness of the numbers eliminated will get less . And obviouslly you will get the numbers . On 1/25/11, siddharth

Re: [algogeeks] Re: Prime Numbers

2011-01-26 Thread siddharth srivastava
Hey Dave On 25 January 2011 18:17, Dave wrote: > The most efficient approach is to google "millionth prime number" and > select the first hit. > > Good one. But it was asked to me in an interview. The trivial approach would be to check for every number to be a prime an continue till the count of

[algogeeks] Re: Prime Numbers

2011-01-25 Thread Dave
The most efficient approach is to google "millionth prime number" and select the first hit. Dave On Jan 25, 6:00 am, siddharth srivastava wrote: > Hi > > Its an easy one but still I am looking for the most efficient approach. > > Find first 1 million prime numbers. > > -- > Siddharth Srivastava