//Preconditions
//Problem definition
val problemSource
= 0x98765432
val problem
: Int
= problemSource
* multiplier
println(s"$problemSource * $multiplier = $problem")
//Resolution
val problemAsLong
= problem.
toLong & 0xFFFFFFFFL
val overflowBit
= 0x100000000L
for(test
<-
0 until multiplier
) { if((problemAsLong + overflowBit
* test
) % multiplier
== 0) { val originalLong
= (problemAsLong + overflowBit
* test
) / multiplier
val original
= originalLong.
toInt println(s"$original (test = $test)")
}
}
}
b2JqZWN0IE1haW4gZXh0ZW5kcyBBcHAgewogIC8vUHJlY29uZGl0aW9ucwogIHZhbCBtdWx0aXBsaWVyID0gMzMKCiAgLy9Qcm9ibGVtIGRlZmluaXRpb24KICB2YWwgcHJvYmxlbVNvdXJjZSA9IDB4OTg3NjU0MzIKICB2YWwgcHJvYmxlbTogSW50ID0gcHJvYmxlbVNvdXJjZSAqIG11bHRpcGxpZXIKICBwcmludGxuKHMiJHByb2JsZW1Tb3VyY2UgKiAkbXVsdGlwbGllciA9ICRwcm9ibGVtIikKCiAgLy9SZXNvbHV0aW9uCiAgdmFsIHByb2JsZW1Bc0xvbmcgPSBwcm9ibGVtLnRvTG9uZyAmIDB4RkZGRkZGRkZMCiAgdmFsIG92ZXJmbG93Qml0ID0gMHgxMDAwMDAwMDBMCiAgZm9yKHRlc3QgPC0gMCB1bnRpbCBtdWx0aXBsaWVyKSB7CiAgICBpZigocHJvYmxlbUFzTG9uZyArIG92ZXJmbG93Qml0ICogdGVzdCkgJSBtdWx0aXBsaWVyID09IDApIHsKICAgICAgdmFsIG9yaWdpbmFsTG9uZyA9IChwcm9ibGVtQXNMb25nICsgb3ZlcmZsb3dCaXQgKiB0ZXN0KSAvIG11bHRpcGxpZXIKICAgICAgdmFsIG9yaWdpbmFsID0gb3JpZ2luYWxMb25nLnRvSW50CiAgICAgIHByaW50bG4ocyIkb3JpZ2luYWwgKHRlc3QgPSAkdGVzdCkiKQogICAgfQogIH0KfQo=