-
Notifications
You must be signed in to change notification settings - Fork 0
/
hr_superdigit.scala
46 lines (37 loc) · 979 Bytes
/
hr_superdigit.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import scala.annotation.tailrec
import scala.io.StdIn.readLine
object Solution {
def make_p(n: BigInt, k: Int): BigInt = {
return BigInt(n.toString.map(_.asDigit).sum) * k
}
def superdigit(p: BigInt): Int = {
return (1 + (p - 1) % 9).toInt
}
def main(args: Array[String]) {
val nk = readLine().split(" ")
val n = BigInt(nk(0))
val k = nk(1).toInt
val p = make_p(n, k)
println(superdigit(p))
}
}
/*
object Solution {
def make_p(n: String, k: Int): String = {
return n * k
}
@tailrec
def superdigit(p: String): Int = {
if (p.size == 1) return p.toInt
val new_p = p.map(_.asDigit).sum.toString
return superdigit(new_p)
}
def main(args: Array[String]) {
val nk = readLine().split(" ")
val n = nk(0)
val k = nk(1).toInt
val p = make_p(n, k)
println(superdigit(p))
}
}
*/