reviewed
approved
reviewed
approved
proposed
reviewed
editing
proposed
After the missing a(6) the sequence continues: 4, 1, 0, 12, 14.
approved
editing
proposed
approved
editing
proposed
Least k such that the sum triangular(k) + triangular(k+1) +...+ triangular(k+n-1) is a triangular number, or -1 if no such k exists.
proposed
editing
editing
proposed
(C99)
#include <stdio.h>
#include <math.h>
int main() {
unsigned long long a, s, n, i;
for (n=1; n < 100; ++n) {
for (a=i=0; i<n; ++i)
a += i*(i+1)/2;
s = sqrt(a*2);
if (s*(s+1) == a*2) { printf("%llu, ", i-n); continue; }
for (i = n; ; ++i) {
a -= (i-n)*(i-n+1)/2;
a += i*(i+1)/2;
if (a>=(1ULL<<63)) { printf("-, "); break; }
s = sqrt(a*2);
if (s*(s+1) == a*2) { printf("%llu, ", i-n); break; }
}
}
return 0;
}
proposed
editing