Increasing gaps between consecutive Niven numbers: Difference between revisions

Content added Content deleted
m (Minor edit to C code)
m (Minor edit to C++ code)
Line 123: Line 123:
// Returns the sum of the digits of n given the
// Returns the sum of the digits of n given the
// sum of the digits of n - 1
// sum of the digits of n - 1
uint64_t digit_sum(uint64_t n, int sum) {
uint64_t digit_sum(uint64_t n, uint64_t sum) {
++sum;
++sum;
while (n > 0 && n % 10 == 0) {
while (n > 0 && n % 10 == 0) {
Line 142: Line 142:
std::cout.imbue(std::locale(""));
std::cout.imbue(std::locale(""));


uint64_t previous = 1, gap = 0;
uint64_t previous = 1, gap = 0, sum = 0;
int niven_index = 0, gap_index = 1, sum = 0;
int niven_index = 0, gap_index = 1;


std::cout << "Gap index Gap Niven index Niven number\n";
std::cout << "Gap index Gap Niven index Niven number\n";