# All numbers 1 < n < 100 , such that n congruent to 1 modula 23 !
arithmetic_progression(1, 23, 5) # or
N <- 1:100; N[mod(N, 23)==1] # 1 24 47 70 93
# To generate the arithmetic progression from a to b with d as difference:
# n = floor((b-a)/d)+1
# arithmetic_progression(a, d, n)
n <- floor((100-1)/23) + 1 # 5
arithmetic_progression(1, 23, n) # 1 24 47 70 93
# Primes in arithmetic progressions:
n1 <- arithmetic_progression(5, 4, 1000) # 5 9 13 17 21 25 29 ...
n3 <- arithmetic_progression(3, 4, 1000) # 3 7 11 15 19 23 27 ...
length(n1[isPrime(n1)]) # 269
length(n1[isPrime(n3)]) # 280
# Sum of squares of reciprocals of an arithmetic progression:
a = 7; d = 11; n = 1000
sum(1/arithmetic_progression(a, d, n)^2) # 0.0272888
# = trigamma(a/d)/d^2 # 0.0272971
Run the code above in your browser using DataLab