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 less thanabout 0.5035 seconds.
<syntaxhighlight lang="c">#include <stdio.h>
#include <stdint.h>
Line 55:
 
int findNearestInArray(GArray *a, uint64_t n) {
int il = 0, r = a->len, m;
forwhile (i = 0; il < a->len; ++ir) {
ifm = (g_array_index(a,l uint64_t,+ ir) >= n) return i/2;
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 a->lenr;
}
 
9,477

edits