For this function that calculates the woodall numbers up to n = 64
And the algorithm for a woodall is Wn = n ⋅ 2n - 1
for (int n = 1; n <= 64; ++n)
{
a[n - 1] = (n * (exp2(n))) - 1;
}
But after n
is greater than 47 the results are wrong in that it seems like it is forgetting to - 1
the result of n * (exp2(n))
.
Here is what the output is if i cout
the values via
std::cout << i << ":\t" << std::setprecision(32) << a[i - 1] << std::endl;
... before is correct
n
45: 1583296743997439
46: 3236962232172543
47: 6614661952700415
48: 13510798882111488
49: 27584547717644288
50: 56294995342131200
... after is incorrect
for a[]
is an unsigned long int
The function produces correct results if I separate the - 1
operation out to its own for loop though:
for (int n = 1; n <= 64; ++n)
{
a[n - 1] = (n * (exp2(n)));
}
for (int n = 1; n <= 64; ++n)
{
a[n - 1] = a[n - 1] - 1;
}