Prime numbers

Posts 16–19 of 19 · Page 2 of 2
It means thats the running time for the program, if you compiled his code for 10000 and my code for 10000 my code is like a lot faster
Oh, that's interesting. How did you figure that one out?
Ok you see lala's code:

Code:
 for (prime = 1;prime <=10000; prime++)
Thats about 10000 runs which is n

Now inside that for loop is another for loop!
Code:
for (checker = 1; checker <prime; checker++)
the average of all these runs is about n/2 (5000)

(sorry i was wrong it n*(n/2) not n sqaured)

Now my code:

Code:
for(i=5;i<10000;i+=2)
thats about n/2 (5000) runs for each odd number

Code:
for(i2=0,prime=true;primelist[i2]<=sqrt(i);i2++)
i check the prime list for any factors up to the square root of the number to check

that should be sqrt(n)/2 about the average

so my running time would be: n/2 * sqrt(n)/2 and lalas: n*(n/2)
Quote Originally Posted by zhaoyun333 View Post
Ok you see lala's code:

Code:
 for (prime = 1;prime <=10000; prime++)
Thats about 10000 runs which is n

Now inside that for loop is another for loop!
Code:
for (checker = 1; checker <prime; checker++)
the average of all these runs is about n/2 (5000)

(sorry i was wrong it n*(n/2) not n sqaured)

Now my code:

Code:
for(i=5;i<10000;i+=2)
thats about n/2 (5000) runs for each odd number

Code:
for(i2=0,prime=true;primelist[i2]<=sqrt(i);i2++)
i check the prime list for any factors up to the square root of the number to check

that should be sqrt(n)/2 about the average

so my running time would be: n/2 * sqrt(n)/2 and lalas: n*(n/2)
Oh hey zhao is canadian. As am i. Either way i suppose that makes sense. Probably.
Posts 16–19 of 19 · Page 2 of 2
This thread is closed for replies.

Similar Threads

Talk with us