login
Smallest of three consecutive primes whose average is a triangular number.
5

%I #5 May 29 2013 12:17:59

%S 18713,27253,35227,45433,138587,251677,283861,425489,462221,463189,

%T 486583,634493,694409,826211,943231,1103341,1163557,1181927,1214453,

%U 1282387,1462891,1509439,1925681,1931569,2425487,2970689,3041803,3324323,3605939,3627451,4096933,5140781

%N Smallest of three consecutive primes whose average is a triangular number.

%o (C)

%o #include <stdio.h>

%o #include <stdlib.h>

%o #include <math.h>

%o #define TOP (1ULL<<30)

%o int main() {

%o unsigned long long i, j, p1, p2, r, s;

%o unsigned char *c = (unsigned char *)malloc(TOP/8);

%o memset(c, 0, TOP/8);

%o for (i=3; i < TOP; i+=2)

%o if ((c[i>>4] & (1<<((i>>1) & 7)))==0 /*&& i<(1ULL<<32)*/)

%o for (j=i*i>>1; j<TOP; j+=i) c[j>>3] |= 1 << (j&7);

%o for (p2=2, p1=3, i=5; i < TOP; i+=2)

%o if ((c[i>>4] & (1<<((i>>1) & 7)))==0) {

%o s = p2 + p1 + i;

%o if ((s%3)==0) {

%o s/=3;

%o r = sqrt(s*2);

%o if (r*(r+1)==s*2) printf("%llu, ", p2);

%o }

%o p2 = p1, p1 = i;

%o }

%o return 0;

%o }

%Y Cf. A076304, A206279, A226145-A226149.

%K nonn

%O 1,1

%A _Alex Ratushnyak_, May 28 2013