fork(1) download
  1. object Main extends App {
  2. //Preconditions
  3. val multiplier = 33
  4.  
  5. //Problem definition
  6. val problemSource = 0x98765432
  7. val problem: Int = problemSource * multiplier
  8. println(s"$problemSource * $multiplier = $problem")
  9.  
  10. //Resolution
  11. val problemAsLong = problem.toLong & 0xFFFFFFFFL
  12. val overflowBit = 0x100000000L
  13. for(test <- 0 until multiplier) {
  14. if((problemAsLong + overflowBit * test) % multiplier == 0) {
  15. val originalLong = (problemAsLong + overflowBit * test) / multiplier
  16. val original = originalLong.toInt
  17. println(s"$original (test = $test)")
  18. }
  19. }
  20. }
  21.  
Success #stdin #stdout 0.4s 382016KB
stdin
Standard input is empty
stdout
-1737075662 * 33 = -1488921998
-1737075662 (test = 19)