I found an algorithm to find the values of the phi function.
Algorithm:
1gc < function (m, n) {
2 while (1) {
3 rem < m %% n # getting the remainder here
4 ifelse (rem == 0, break, { m = n; n = rem; })
5 }
6 n
7}
8
9# eulers phi function
10phi < function (n) {
11 if (n < 0) { 1 } # function's domain are positive integers only
12 sum = 0
13 for (k in 1:n) {
14 if (gc(n, k) == 1) { sum = sum + 1 }
15 } # k is a totient of n.
16}
17
18value < NULL
19for (i in 1:1000) {
20value < c(val
This can be programmed in C++, I don´t know if the algorithm is fast
Last fiddled with by MathDoggy on 20190324 at 23:27
