Jump to content

  • Log In with Google      Sign In   
  • Create Account


Member Since 08 May 2010
Offline Last Active Mar 11 2013 11:21 AM

#5007816 Any faster way to calculate prime number?

Posted by on 06 December 2012 - 11:25 AM

I am wondering if there is any fast way to calculate all the prime numbers within a given number N. Like give N = 10 it will produce 1,2,3,5,7
My version is divide only odd numbers by those already calculated prime numbers.
int n = 1000;
int half = n/2;
//At most n/2 prime numbers but when n is realy big this speculation is far from the accually size which is a waste(any way to solve it?)
int* temp = new int[half];
int count = 0;
if (n>3)
  count = 3;
  for (int x=5;x<=n;x=x+2)
   int y;
   for(y =1; y<count;y++){
    if (x%temp[y] == 0)
     //x is not a prime number
	 y = count+1;
   if (y == count)
   //x is a prime number
    temp[count] = x;
  count = n;
  for (int x=0;x<n;x++)
   temp[x] = x+1;
// create another array which has the exact size as needed then delete the temp
int* p = new int[count];
for (int z = 0; z<count; z++)
  p[z] = temp[z];
delete [] temp;

Any problem with this one or any faster way?

#4977951 Can not get my font rendered in DX9

Posted by on 08 September 2012 - 05:13 AM

Cool I will do Thanks in advance

#4977829 Can not get my font rendered in DX9

Posted by on 07 September 2012 - 04:03 PM

Thank you so much Yewbie This really help me a lot
Yeah I have seen the link. It looks like DrawText is a function embeded in windows development. Reckon the function in DirectX works in the same way coz it is by microsoft as well : )

#4977788 Can not get my font rendered in DX9

Posted by on 07 September 2012 - 01:15 PM

- I know you are using DT_CALCRECT, but just try adding a width and height to your right and bottom and see if it displays.

Thanks yewbie I get it solved by using
kText.bottom = iY+100;
kText.top = iY;
kText.left = iX;
kText.right = iX+100;

ms_hResult = m_kFontArray[m_iFontID]->DrawText(
0, // pSprite
acText, // pString
-1, // Count
&kText, // pRect

Really want to know what is the problem of the previous one Posted Image

#4960912 Run-Time Check Failure #2

Posted by on 19 July 2012 - 06:43 AM

Thanks Hodgman

Yeah that is the place where goes wrong. I will be more careful next time.