I need to develop an algorithm that takes a number M and finds a number that his inverse (inverse numbers: 24-42, also 0s dont count so another example is 24000- 42)summed with him makes M.
Example the number 908 is given, one solution is 256.
M can be as high as 10^100000
I need to develop an algorithm that takes a number M and finds a number that his inverse (inverse numbers: 24-42...
in what base?
Take your image's advice and contemplate suicide
Why?
decimal
I just want ideas or whatever
>Example the number 908 is given, one solution is 256.
This doesn't make sense. It sounds like your algorithm is "find N such that M=INVERSE(M)+N" however, INVERSE(908) is 89, and 89 + 256 = 345.
Idea: one of the two numbers must be less than M/2
that was a fault of mine, zeros on the right or left are not considered
find N such that M=INVERSE(N)+N
Why the hell would zeros not be considered if on the right.
that was my first idea also but then i came to the conclusion that you cant treat these numbers like numbers but more like arrays of single numbers because of their size
because then they go left and 0042=42
Wouldn't they not matter in inverse?
Inverse of 0010 is 0100 or 010000 or 01
inversion happens from the first non-zero digit starting from the right
Hint, the difference between a number and its inverse is always a multiple of 9
explain?
321-123=198
198 = 9 * 22
Hint, the difference between a number and its inverse is always a multiple of 9
not the case if you ignore zeroes as OP mentioned
2400-42 = 2358 = 9 * 262
Yes but can this info be used to achieve the desired outcome
zeroes just multiply that difference by ten so it also applies then
What university/college OP?
M - 2*N is divisible by 9
could you imagine dividing numbers of the size 10^1000000
Modular arithmetic for huge numbers trivial
It's pretty easy to prune number based on whether or not the number is odd or even.
Consider the case M = 908 and current N being checked is 43, an odd number.
Its inverse, 34, is an even number, which means you get an odd number from its result.
To save the algorithm some search time, you can skip numbers based on this. If you do it right, you don't even need to perform modulus.
I'd try to help you if you could write a coherent English sentence