-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD1.kt
55 lines (47 loc) · 1.15 KB
/
D1.kt
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
46
47
48
49
50
51
52
53
54
fun main() {
val input = System.`in`.bufferedReader()
val output = StringBuilder()
fun kxor(aa: Int, bb: Int, k: Int) : Int {
var a = aa
var b = bb
var ans = 0
var mul = 1
while(a > 0 || b > 0) {
ans += ( (a % k + b % k) % k ) * mul
mul *= k
a /= k
b /= k
}
return ans
}
fun kxori(aa: Int, bb: Int, k: Int) : Int {
var a = aa
var b = bb
var ans = 0
var mul = 1
while(a > 0 || b > 0) {
ans += ( (a % k - b % k + k) % k ) * mul
mul *= k
a /= k
b /= k
}
return ans
}
val t = readLine()!!.toInt()
repeat(t) {
var(n, k) = readLine()!!.split(' ').map { it.toInt() }
var x = 0
for(ans in 0 until n) {
var query = kxor(x, ans, k)
if(ans % 2 == 1) {
query = kxori(x, ans, k)
}
println(query)
var r = readLine()!!.toInt()
if(r == 1) {
break
}
x = kxori(query, x, k)
}
}
}