View Single Post
Old 2019-03-24, 23:27   #5
MathDoggy
 
Mar 2019

5·11 Posts
Default

I found an algorithm to find the values of the phi function.
Algorithm:


1-gc <- 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
10-phi <- 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-
18-value <- NULL
19-for (i in 1:1000) {
20-value <- c(val

This can be programmed in C++, I don´t know if the algorithm is fast

Last fiddled with by MathDoggy on 2019-03-24 at 23:27
MathDoggy is offline   Reply With Quote