login
Primes p such that p-1 is a square and p-2 is a triangular number.
6

%I #8 Jan 30 2014 13:09:05

%S 2,5,17,17957,4726277,23911673957

%N Primes p such that p-1 is a square and p-2 is a triangular number.

%C Roots of squares: a(n)-1 = b(n)*b(n), b(n) = A226070(n).

%C Roots of triangular numbers: a(n)-2 = c(n)*(c(n)+1)/2, c(n) = A226071(n).

%C Primes of the form A006452(k)^2+1. a(7) is too large to include here (see b-file). - _Max Alekseyev_, Jan 30 2014

%H Max Alekseyev, <a href="/A226069/b226069.txt">Table of n, a(n) for n = 1..12</a>

%o (C)

%o #include <stdio.h>

%o #include <stdlib.h>

%o #include <math.h>

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

%o int main() {

%o unsigned long long i, j, k, r, n=1;

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

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

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

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

%o ++n;

%o if (i<(1ULL<<32))

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

%o }

%o //printf("%llu\n", n);

%o for (i=1, j=i*i+1; j < TOP*2; i++,j=i*i+1)

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

%o k = j-2;

%o r = sqrt(k*2);

%o if (r*r+r==k*2) printf("%9llu %9llu %9llu\n", r, i, j);

%o }

%o free(c);

%o return 0;

%o }

%Y Cf. A226070-A226074.

%K nonn

%O 1,1

%A _Alex Ratushnyak_, May 25 2013

%E Terms a(7)-a(12) from _Max Alekseyev_, Jan 30 2014