Increasing gaps between consecutive Niven numbers: Difference between revisions
Content added Content deleted
m (Minor performance improvement) |
m (Minor performance improvement) |
||
Line 36: | Line 36: | ||
{{trans|C++}} |
{{trans|C++}} |
||
<lang c>#include <locale.h> |
<lang c>#include <locale.h> |
||
#include <stdbool.h> |
|||
#include <stdint.h> |
#include <stdint.h> |
||
#include <stdio.h> |
#include <stdio.h> |
||
Line 48: | Line 49: | ||
} |
} |
||
return sum; |
return sum; |
||
} |
|||
inline bool divisible(uint64_t n, uint64_t d) { |
|||
if ((d & 1) == 0 && (n & 1) == 1) |
|||
return false; |
|||
return n % d == 0; |
|||
} |
} |
||
Line 59: | Line 66: | ||
for (uint64_t niven = 1; gap_index <= 32; ++niven) { |
for (uint64_t niven = 1; gap_index <= 32; ++niven) { |
||
sum = digit_sum(niven, sum); |
sum = digit_sum(niven, sum); |
||
if (niven |
if (divisible(niven, sum)) { |
||
if (niven > previous + gap) { |
if (niven > previous + gap) { |
||
gap = niven - previous; |
gap = niven - previous; |