%I #49 Mar 05 2022 14:17:33
%S 1,0,1,3,4,2,4,2,5,7,5,8,4,2,8,2,7,5,11,7,5,12,8,2,8,4,2,13,11,7,9,5,
%T 16,14,4,2,14,8,4,17,11,9,19,17,13,11,20,8,4,2,20,14,12,2,19,13,7,5,
%U 23,19,17,7,18,14,12,8,20,14,4,2,25,19,11,5,27,23,17,9,5,26,16,14,4,2,26
%N Difference between the smallest triangular number >= n-th prime and the n-th prime.
%H Jens Kruse Andersen, <a href="/A243111/b243111.txt">Table of n, a(n) for n = 1..10000</a>
%e x, 0 , x , x , x
%e 0 0 0 0 0 0 x x x x
%e 0 0 0 0 0 0 0 0 x
%e 0 0 0 0 0 0 0 0
%e 0 0 0 0 0
%e prime(n) = 2,3,5,7,11,...
%e x -> we need respectively 1, 0, 1, 3 and 4 numbers to complete the whole triangle.
%t Module[{upto=100,tnos},tnos=Accumulate[Range[Ceiling[(Sqrt[8*Prime[upto]+ 1]- 1)/2]]];Table[SelectFirst[tnos,#>=Prime[n]&]-Prime[n],{n,upto}]] (* _Harvey P. Dale_, Jan 15 2015 *)
%o (PARI)
%o a(n)=k=1;while(k*(k+1)/2<prime(n),k++);return(k*(k+1)/2-prime(n))
%o vector(100,n,a(n)) \\ _Derek Orr_, Aug 21 2014
%Y Cf. A000040, A002262, A000217.
%K nonn,easy
%O 1,4
%A _Odimar Fabeny_, Aug 20 2014