How to do this? Arrays and math

• 08-11-2002
brian0918
How to do this? Arrays and math
This is probably something simple, but know hardly any C++.

What I need to do is:

I have an __int64 N (a 64 bit integer) that is set equal to a number. I want to mod (%) N with each number in this array:

unsigned const long primetable[] =
{
3, 5, 7, 11, 13, 17, 19, 23,
29, 31, 37, 41, 43, 47, 53, 59, 61
};

it starts with the first one, then loops to the next... and stops modding before the CURRENT NUMBER in the array gets greater than:

(long)sqrt(N)

I also have to be able to test each mod to see if the result is zero. It needs to be some kind of for-loop.

Oh, also-- The array I have above isn't the complete one. The actual one is extremely long and contains thousands of separate numbers.

What's stopping me is a lack of knowledge of the syntax, or anything about arrays or array manipulation. Any help would be great! Thanks.
• 08-11-2002
SilentStrike
Code:

```#include <iostream> #define NUM_ELEMENTS(n) (sizeof n / sizeof n[0]) unsigned const long primetable[] = { 2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61 }; int main() {         int test_min = 5, test_max = 500;         for (int someTest = test_min; someTest < test_max; someTest++) {                 bool is_prime=true;                 // breaks if sqrt(someTest) > last entry in primetable                 for (int i = 0; i < NUM_ELEMENTS(primetable); ++i) {                         if (someTest % primetable[i] == 0) {                                 is_prime=false;                                 break;                         }                 }                                 if (is_prime) {                         std::cout << someTest << " is prime" << std::endl;                 } else {                         std::cout << someTest << " is not prime" << std::endl;                 }         }         return 0; }```