Jordan-Pólya numbers: Difference between revisions
→{{header|C}}: Now uses a binary search on the GArray - about 15 times quicker than before.
(Added C) |
(→{{header|C}}: Now uses a binary search on the GArray - about 15 times quicker than before.) |
||
Line 28:
{{trans|Wren}}
{{libheader|GLib}}
A translation of the second version. Run time
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdint.h>
Line 55:
int findNearestInArray(GArray *a, uint64_t n) {
int
if (g_array_index(a, uint64_t, m) > n) {
r = m;
} else {
l = m + 1;
}
}
if (r > 0 && g_array_index(a, uint64_t, r-1) == n) return r - 1;
return
}
|