Initial data commit
This commit is contained in:
parent
72d218235f
commit
f23f22d71c
199087 changed files with 3378941 additions and 0 deletions
14
Task/Totient-function/Scala/totient-function-2.scala
Normal file
14
Task/Totient-function/Scala/totient-function-2.scala
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
def totientPrd(num: Int): Int = {
|
||||
@tailrec
|
||||
def dTrec(f: Int, n: Int): Int = if(n%f == 0) dTrec(f, n/f) else n
|
||||
|
||||
@tailrec
|
||||
def tTrec(ac: Int, i: Int, n: Int): Int = if(n != 1){
|
||||
if(n%i == 0) tTrec(ac*(i - 1)/i, i + 1, dTrec(i, n))
|
||||
else tTrec(ac, i + 1, n)
|
||||
}else{
|
||||
ac
|
||||
}
|
||||
|
||||
tTrec(num, 2, num)
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue