Array problem

¿how big is n? ¿what time complexity would you allow?
> O(n2) is not passing
When brute force doesn't work, you have to put down the keyboard, step away from the mouse and grab some paper and a pencil.

Puzzles like this are solved by you thinking smarter, not by making the machine work harder.

So you have (A+B) % A == 0 or (A+B) % B == 0

Now ask yourself some questions like
- what if A or B are prime, are there ever any possible solutions?
- do A and B have any common factors?
- what if A is odd and B is even?

Find things you can use to make the program you write much more efficient at solving the problem.


Remember that (A+B) == (B+A), in case you were trying some silly permutation.
answer salem c's questions first
1 to 10^5 --- chef strikes again
These kinds of problems require some mathematical knowledge. You have already been given some very helpful hints.
Topic archived. No new replies allowed.