Hot_Potato's blog

By Hot_Potato, history, 5 years ago, In English

Find a pair of integers (A,B) such that A**5 − B**5 =X for a given integer X..this is from atcoder beginner level contest...How to solve this ? I checked the editorial but it's not clear.

https://atcoder.jp/contests/abc166/tasks/abc166_d .

  • Vote: I like it
  • +2
  • Vote: I do not like it

| Write comment?
»
5 years ago, # |
  Vote: I like it +1 Vote: I do not like it

Try all $$$A$$$ from $$$-1000$$$ to $$$1000$$$ and $$$B$$$ from $$$-1000$$$ to $$$1000$$$, print anything that works.

»
5 years ago, # |
Rev. 2   Vote: I like it +9 Vote: I do not like it

There are limited number of possible combinations one can possible devise. for example if you take 500 for A and even if you subtract from even largest number 499 , you still be getting number > 10**9,so going till 500 is not required . Just check combinations till 126 as some have said in the discussion, i did with 1000

»
5 years ago, # |
  Vote: I like it 0 Vote: I do not like it

You can rewrite the expression as b^5=a^5-x now you can run loop on a from 0 to x^(1/5) and filter those values of a for which a^5-x is perfect 5th power of some integer. From this you can find pair a,b which satisfy given condition.