我正在对大数进行素数分解(主要是project 3 @ project Euler。我需要对声明为 long long 的数字使用模数。每次我尝试对那个巨大的数字求模时,我都会得到一个浮点异常。任何帮助都是非常感谢。谢谢。
我已经通过 gdb 运行了这个,看看发生了什么。下面是我的代码。在这一点上这是非常粗略的逻辑。 请不要给我问题的答案。我很乐意接受帮助以使这更好,只是请不要给我直接的答案。谢谢 :)
long factor(long number) {
string br = "\n\r";
long x = 0;
/*this modulus variable is an attempt
to move the answer into a long long container
to see if that solves my floating point exception,
it didn't*/
long long modulus;
while(x <= number) {
modulus = number % x;
if(modulus == 0) {
cout << number/x << br;
return factor(number/x);
}//if number % x
else {
return x;
}//else
x++;
}//while
}//factor