Ale*_*lex 3 c++ floating-point-exceptions
我有一个似乎无法解决的问题.我随机生成数字以确定我的数字是否是相对论素数.
这是给我一个浮点异常的函数:
bool modularExponentiationTest(unsigned long long exponent, unsigned long long modulus)
{
short index = 0;
unsigned long long base;
unsigned long long result;
do
{
result = 1;
base = rand() % exponent; // <--CAUSED BY THIS
while (exponent > 0)
{
if (exponent & 1)
result = (result * base) % modulus;
exponent >>= 1;
base = (base * base) % modulus;
}
if (result != 1)
return false;
}while(++index < 10);
return true;
}
Run Code Online (Sandbox Code Playgroud)
通过执行以下操作,我在不同的函数中实现随机种子:
srand(time(NULL));
Run Code Online (Sandbox Code Playgroud)
非常感谢您的帮助!
| 归档时间: |
|
| 查看次数: |
4128 次 |
| 最近记录: |