Fermat numbers: Difference between revisions
Content added Content deleted
m (Minor performance improvement) |
m (Performance improvement) |
||
Line 123: | Line 123: | ||
{{trans|Java}} |
{{trans|Java}} |
||
{{libheader|Boost}} |
{{libheader|Boost}} |
||
Built and tested on macOS 10.15 |
Built and tested on macOS 10.15, CPU: 3.2 GHz Intel Core i5. |
||
Execution time is about |
Execution time is about 12 minutes. |
||
<lang cpp>#include <iostream> |
<lang cpp>#include <iostream> |
||
#include <vector> |
#include <vector> |
||
Line 140: | Line 140: | ||
} |
} |
||
inline |
inline void g(integer& x, const integer& n) { |
||
x *= x; |
|||
x += 1; |
|||
x %= n; |
|||
} |
} |
||
Line 148: | Line 150: | ||
int count = 0; |
int count = 0; |
||
for (;;) { |
for (;;) { |
||
g(x, n); |
|||
g(y, n); |
|||
g(y, n); |
|||
d = abs(x - y); |
d = abs(x - y); |
||
z = (z * d) % n; |
z = (z * d) % n; |