login
Sum of the digits of the n-th prime number in balanced ternary.
0

%I #15 Jan 13 2020 17:45:52

%S 0,1,-1,1,1,3,-1,1,-1,1,3,3,-3,-1,-1,-1,-1,1,3,-1,1,1,1,1,1,1,3,1,3,1,

%T -1,-3,-1,1,-3,-1,1,1,-1,1,-1,1,1,3,1,3,1,1,1,3,-1,-1,1,1,-1,1,1,3,3,

%U 3,5,-1,3,-1,1,1,3,5,1,3,3,3,-3,-1,-1,-3,-1,-1,-3,1,-3,-1,-1,1,1,1,-3,-1,-1,1,-1,-1,1,-1,3,-1,-1,1,3,1

%N Sum of the digits of the n-th prime number in balanced ternary.

%H Wikipedia, <a href="https://en.wikipedia.org/wiki/Balanced_ternary">Balanced ternary</a>

%F a(n) = A065363(A000040(n)). - _Alois P. Heinz_, Jan 09 2020

%e Using T for -1 and _bt as suffix for balanced ternary: 2_10 = 1T_bt, sum of digits is zero; 3_10 = 10_bt, sum of digits is 1 and 5_10 = 1TT, sum of digits = -1.

%p b:= proc(n) `if`(n=0, 0, (d-> `if`(d=2,

%p b(q+1)-1, d+b(q)))(irem(n, 3, 'q')))

%p end:

%p a:= n-> b(ithprime(n)):

%p seq(a(n), n=1..100); # _Alois P. Heinz_, Jan 09 2020

%o (C)

%o #include <stdio.h>

%o #include <math.h>

%o #define N 1000 /* Largest prime considered - 1 */

%o char x[N];

%o int main()

%o {

%o int i, n, v, s, r;

%o for (i=4; i<N; i+=2)

%o x[i] = 1;

%o for (n=3; n<sqrt(N*1.0); n +=2)

%o for (i=n+n; i<N; i+=n)

%o x[i] = 1;

%o for (n = 2; n < N; n++) {

%o if (x[n] == 0) {

%o v = n;

%o s = 0;

%o while (v != 0) {

%o r = v % 3;

%o if (r == 2)

%o r = -1;

%o s = s + r;

%o v = (v - r) / 3;

%o }

%o printf("%d,",s);

%o }

%o }

%o printf("\n");

%o }

%Y See A007605 (sum of digits of primes in base 10); A239619 (sum of digits of primes in base 3).

%Y Cf. A000040, A065363, A117966.

%K sign,base,easy

%O 1,6

%A _Thomas König_, Jan 09 2020