Gladly will I share the "mindless programming" patent, but I'm keeping the "totally mindless programming" patent, for myself!
One way I've worked with problems like this (too much data for an array), is to have a for loop inside the innermost while() loop. When the biggest array you can handle is full (by testing you know this already), you call the function that tests all the numbers.
When the testing on those numbers is finished, control returns to the while loops, and they pick up where they left off, very neatly. I would not call the test function for every number - just for the whole string array, when you have 40,000 or whatever you can handle, in the string array, full.
Upon it's return, you exit the for loop, and the counter is reset to 0 again. Works well, easy to code, and I don't know of anything faster.