Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
3
Task/Totient-function/Scala/totient-function-1.scala
Normal file
3
Task/Totient-function/Scala/totient-function-1.scala
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
@tailrec
|
||||
def gcd(a: Int, b: Int): Int = if(b == 0) a else gcd(b, a%b)
|
||||
def totientLaz(num: Int): Int = LazyList.range(2, num).count(gcd(num, _) == 1) + 1
|
||||
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)
|
||||
}
|
||||
3
Task/Totient-function/Scala/totient-function-3.scala
Normal file
3
Task/Totient-function/Scala/totient-function-3.scala
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
@tailrec
|
||||
def scrub(f: Long, num: Long): Long = if(num%f == 0) scrub(f, num/f) else num
|
||||
def totientLazPrd(num: Long): Long = LazyList.iterate((num, 2: Long, num)){case (ac, i, n) => if(n%i == 0) (ac*(i - 1)/i, i + 1, scrub(i, n)) else (ac, i + 1, n)}.find(_._3 == 1).get._1
|
||||
Loading…
Add table
Add a link
Reference in a new issue