Mapping two integers to one, in a unique and deterministic way

前端 未结 19 2584
不知归路
不知归路 2020-11-22 09:35

Imagine two positive integers A and B. I want to combine these two into a single integer C.

There can be no other integers D and E which combine to C. So combining

19条回答
  •  说谎
    说谎 (楼主)
    2020-11-22 10:21

    Is this even possible?
    You are combining two integers. They both have the range -2,147,483,648 to 2,147,483,647 but you will only take the positives. That makes 2147483647^2 = 4,61169E+18 combinations. Since each combination has to be unique AND result in an integer, you'll need some kind of magical integer that can contain this amount of numbers.

    Or is my logic flawed?

提交回复
热议问题