%I #33 Jun 25 2023 03:31:26
%S 7,11,23,59,107,227,503,1019,2039,4079,8147,16223,32603,65267,130787,
%T 262127,524243,1048343,2097143,4194287,8388287,16776899,33553799,
%U 67108187,134217323,268435019,536870723,1073740439,2147483579,4294967087
%N Largest safe prime less than 2^n.
%C Largest safe prime (A005385) p=2*q+1, q also prime (A005384), that can be represented using n binary digits.
%H Gokberk Yaltirakli, <a href="/A243916/b243916.txt">Table of n, a(n) for n = 3..1024</a> (terms 3..100 from Harvey P. Dale)
%t lsp[n_]:=Module[{sp=NextPrime[2^n,-1]},While[!PrimeQ[(sp-1)/2],sp= NextPrime[ sp,-1]];sp]; Array[lsp,35,3] (* _Harvey P. Dale_, Feb 10 2019 *)
%o (MIT/GNU Scheme, with Aubrey Jaffer's SLIB Scheme library)
%o (require 'factor) ;; For prime? predicate.
%o (define (A243916 n) (if (< n 3) 0 (let loop ((i (- (expt 2 n) 1))) (cond ((and (prime? i) (prime? (/ (- i 1) 2))) i) (else (loop (- i 2)))))))
%o ;; _Antti Karttunen_, Jun 18 2014
%o (Python)
%o from sympy import isprime
%o def a(n):
%o if n<3: return 0
%o i=2**n - 1
%o while True:
%o if isprime(i) and isprime((i - 1)/2): return i
%o else: i-=2 # _Indranil Ghosh_, Jun 12 2017, after _Antti Karttunen_'s Scheme Code
%Y Cf. A005385, A005384, A000079.
%K nonn
%O 3,1
%A _José Eduardo Gaboardi de Carvalho_, Jun 18 2014
|