I'm running it now with long long x. It's hanging up on 716151937 again, so I'll need to optimize it a bit, but it's not returning negatives, so that's a huge step up. Thanks for that.
Edit: As I wrote that message another factor came up, so it's just super slow, which I 'll worry about once I get this working.
Awesome! Step 1 is complete.
I am trying to return a value of these factors as a variable of prime, now. prime will be the modulus of the factor (x) and a dividend (a). a will keep rising through numbers until it hits the limit, but that is irrelevent at the moment because when I have prime display itself, it returns as one no matter what. Any suggestions as to how I am doing this wrong?
Here is the code reflecting this next step. I checked my variables, so it's all capable of storing, but for some reason the != 0 in the if statement doesn't work correctly:
Code: Select all
/*
Project Euler Problem 3 - I can produce all factors of a number; but it
stops working when I go for the prime number
Also, large numbers murders it.
*/
#include <cstdio>
#include <cstdlib>
#include <iostream>
using namespace std;
int main(int nNumberofArgs, char* pszArgs[])
{
long long x = 1LL;
long long a = 2;
long long limit = 13195LL;
long long factor = 0LL;
int prime = 0;
for (;x <= limit; x++)
{
factor = limit % x;
if (factor == 0)
{
for (; a <= limit; a++)
{
prime = x % a;
if (prime != 0)
{
cout << x
<< " is a prime factor of "
<< limit
<< "."
<< endl;
}
}
}
}
//wait until user is ready before terminating program
//to allow the user to see the program results
system ("pause");
return 0;
}

