|
|
A331112
|
|
Sum of the digits of the n-th prime number in balanced ternary.
|
|
0
|
|
|
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, -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, 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
(list;
graph;
refs;
listen;
history;
text;
internal format)
|
|
|
OFFSET
|
1,6
|
|
LINKS
|
|
|
FORMULA
|
|
|
EXAMPLE
|
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.
|
|
MAPLE
|
b:= proc(n) `if`(n=0, 0, (d-> `if`(d=2,
b(q+1)-1, d+b(q)))(irem(n, 3, 'q')))
end:
a:= n-> b(ithprime(n)):
|
|
PROG
|
(C)
#include <stdio.h>
#include <math.h>
#define N 1000 /* Largest prime considered - 1 */
char x[N];
int main()
{
int i, n, v, s, r;
for (i=4; i<N; i+=2)
x[i] = 1;
for (n=3; n<sqrt(N*1.0); n +=2)
for (i=n+n; i<N; i+=n)
x[i] = 1;
for (n = 2; n < N; n++) {
if (x[n] == 0) {
v = n;
s = 0;
while (v != 0) {
r = v % 3;
if (r == 2)
r = -1;
s = s + r;
v = (v - r) / 3;
}
printf("%d, ", s);
}
}
printf("\n");
}
|
|
CROSSREFS
|
See A007605 (sum of digits of primes in base 10); A239619 (sum of digits of primes in base 3).
|
|
KEYWORD
|
sign,base,easy
|
|
AUTHOR
|
|
|
STATUS
|
approved
|
|
|
|