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]]


1

Here's a functional approach without using loops: st[p_] := PrimeQ[Total @ IntegerDigits @ p + Range[-3, 1]] ~ AllTrue ~ Not // Not nextStubborn[p_] := NestWhile[NextPrime, NextPrime[p], st] stubbornList[n_] := NestList[nextStubborn, 2, n] // Rest stubbornList[100] (* {8999, 18899, 19889, 19979, 19997, 28979, 29789, 29879, 35999, 36899, *) (* 37799, ...


1

j = 1; While[ Or @@ (PrimeQ@({#-3,# - 2, # - 1, #, # + 1} &@(Total@ IntegerDigits[Prime[j]]))), j++] Prime[j] So 8999 has desired property: {#-3,# - 2, # - 1, #, # + 1} &@(Total@IntegerDigits[Prime[1117]])) yields:{32, 33, 34, 35, 36} for fun: query[u_] := Nor @@ PrimeQ[# + {-3, -2, -1, 0, 1} &@Total[IntegerDigits@u]] cand = ...


1

From the definition in R and testing: fac[n_, p_] := Or @@ (FactorInteger[n][[All, 1]] == # & /@ (Rest@Subsets[p])) nc[n_, p_] := NestWhile[# + 1 &, n, ! fac[#, p] &] Some R examples: and nc[#, {2, 3, 5}] & /@ {47, 100, 101, 1001, 10001} yields: {48, 100, 108, 1024, 10125} Similarly, nc[103, {3, 5, 7}] nc[1017, {7, 11, 13}] ...


1

N[1/2] or 1/2., as said in the comments.



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