-2
$\begingroup$

Let the Given Number be 'K'. I need to store a,b numbers inside K. After some modification I need to get both numbers.

$\endgroup$
  • $\begingroup$ Is there some defined range for $a$ and $b$ ? If, for example, both are $<100$, you could calculate $K= a + 10^6 \times b$. Then there are just many zeros between the values ... $\endgroup$ – Matti P. Jul 4 '19 at 9:11
  • 2
    $\begingroup$ What do you mean by "storing numbers inside" another number that is already given? $\endgroup$ – hmakholm left over Monica Jul 4 '19 at 9:13
3
$\begingroup$

You can incode an arbitrary finite number of natural numbers $a_1, \dots a_n$ in one natural number using the fact that the decomposition of natural numbers into prime factors is unique.

Define $$ K = 2^{a_1} \cdot 3^{a_2} \cdot \dots\,\cdot p_n^{a_n}$$ where $p_k$ is the $k$-th prime number. You can recover the $a_k$ by decomposing $K$ into prime factors.

$\endgroup$
0
$\begingroup$

This highly depends on your task. In general, you can generate an arbitrary function $f:N\times N\rightarrow N$ which is bijective and therefore has an inverse function $f^{-1}$. This could be done like labeling a chessboard. Imagine the chessboard has rows and columns which are numbered, then you can decide on some patterns how you label each field with a unique number. By knowing the pattern you can then recover the row and column by the number eg. starting from bottom left to the bottom right and then the row above you can recover the row and column by "label"%8 and "label"/8.

$\endgroup$

Not the answer you're looking for?Browse other questions tagged or ask your own question.