How can I increase the number of digits i can use?
For example, when i use the number 4362206209 (which I know for a fact is prime) it returns 2 as a factor, which it isn't.
Eventually, I would like to get to long (50+ digit) numbers. I know this calculation would take a long time, but i have several (mathematical) tricks for cutting down on the numbers tried... if I could only get the computer do divide it for me.
Here's my code for the simplist program:
Expand|Select|Wrap|Line Numbers
- #include<iostream>
- #include<cmath>
- using namespace std;
- int main (){
- unsigned long int primeNumber, testNumber =1, testResult = 1;
- cin>>primeNumber;
- bool prime=false;
- while (!prime & testNumber <= sqrt(primeNumber)){
- testNumber++;
- testResult = primeNumber % testNumber;
- if (testResult == 0){
- prime = true;
- }
- }
- if(prime){
- cout<<"first factor is : "<<testNumber;
- }
- else{
- cout<<"it's a prime number";
- }
- return 0;
- }