Tag Info

Hot answers tagged

5

Here is a direct implementation of your series formula: a[1] = 1 a[n_] := a[n - 1] + (Prime[n] - 1)/2 You can speed up calculation by memoizing a: a[1] = 1 a[n_] := a[n] = a[n - 1] + (Prime[n] - 1)/2


4

You can also use RecurrenceTable: ClearAll[a, n] RecurrenceTable[{a[n + 1] == a[n] + (Prime[n + 1] - 1)/2, a[1] == 1}, a, {n, 1, 10}] (* {1, 2, 4, 7, 12, 18, 26, 35, 46, 60} *)


3

Prime[n] returns the $n$th prime number, and all primes except Prime[1] are odd. So the following works: Accumulate[Prepend[Table[(Prime[i] - 1)/2, {i, 2, 10}], 1]]



Only top voted, non community-wiki answers of a minimum length are eligible