Current location - Training Enrollment Network - Mathematics courses - What algorithm can two integers do to get a unique integer result? Is there such an algorithm?
What algorithm can two integers do to get a unique integer result? Is there such an algorithm?
Because in mathematical concept, "integer pair" and "ordered integer pair" are enumerable, that is to say, the contract size of these two sets and integer sets.

Here is a brief introduction to the corresponding algorithm between positive integer pairs and positive integers.

Specifically, it can be assumed that all positive integer pairs are sorted from small to large according to the sum of two numbers. If the sum of two numbers is equal, they are sorted from small to large according to the size of the previous number, that is,

In this way, positive integer pairs whose sum is n have exactly N- 1 groups.

Therefore, we can derive an algorithm to get the unique corresponding positive integer (n) from the positive integer pair (a, b): s = a+bn = sum (1... s-2)+a = (s-2) * (s-1)/2+a.

The method of deriving the corresponding positive integer pair (a, b) from the positive integer n is a bit complicated, mainly because it is difficult to find a correct S, usually by method of bisection or square root, and then get a correct S through finite adjustment, thus calculating A and B. 。

For the compilation of all-integer and all-integer pairs, the handling of symbols and zeros will make the problem a little more complicated. By sorting the absolute values, a similar result can be constructed.