[Question]
  [
## Challenge
There are many numbers which can be expressed as the difference of two squares, or as the difference of two cubes, or maybe even higher powers. Talking about squares, there are various ways of writing a number, say 75, as the difference of 2 squares. You can write:
```
75 = (10)^2 - (5)^2 
   = (14)^2 - (11)^2 
   = (38)^2 - (37)^2         
```
So let's talk about the challenge. Firstly, the user enters a number and then he enters a value for n. You need to display all the ways in which that number can be written in the form of aⁿ - bⁿ.
## Input and Output
The input will be the number and the value of n. Your output shall have all such pairs of 'a' and 'b' such that the above-stated condition is met. The first number in the pair must be larger than the second. Please note that **a, b, n and the input number are all positive integers, and n > 1**.
## Examples
```
50, 2 -> (none)
32, 2 -> (9,7), (6, 2)
7, 3 -> (2,1)
665, 6 -> (3, 2)
81, 4 -> (none)
```
## Scoring
This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'") , so the shortest code wins!
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 8 bytes
```
p*ƓIFẹ+d
```
This is a monadic link that takes the number as argument and reads **n** from STDIN.
[Try it online!](https://tio.run/##y0rNyan8/79A69hkT7eHu3Zqp/z/b/Tf3BQA "Jelly – Try It Online")
### How it works
```
p*ƓIFẹ+d  Main link. Argument: k
p         Cartesian product; yield all pairs [b, a] with b and a in [1, ..., k].
  Ɠ       Get; read an integer n from STDIN.
 *        Power; map each [b, a] to [b**n, a**n].
   I      Increments; map each [b**n, a**n] to [a**n-b**n].
    F     Flatten the resulting list of singleton arrays.
     ẹ    Every; find all indices of k in the list we built.
      +   Add k to the indices to correct the offset.
       d  Divmod; map each index j to [j/k, j%k].
```
[Answer]
# [Haskell](https://www.haskell.org/), 42 bytes
```
k#n=[(a,b)|b<-[1..k],a<-[b..k],a^n-b^n==k]
```
[Try it online!](https://tio.run/##y0gszk7Nyfn/P1s5zzZaI1EnSbMmyUY32lBPLztWJxHISoKw4vJ0k@LybG2zY//nJmbmKdgqpORzKQBBQVFmXomCioK5qYKCsoIRipipAaaYsRGmmLkCSMwYRczMzBQoZvYfAA "Haskell – Try It Online")
## Ungolfed with [UniHaskell](https://github.com/totallyhuman/unihaskell) and `-XUnicodeSyntax`
```
import UniHaskell
f     ∷ Int → Int → [(Int, Int)]
f k n = [(a, b) | b ← 1 … k, a ← b … k, a^n - b^n ≡ k]
```
Can't change much else...
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 9 bytes
Very inefficient for larger input values.
```
LãDImÆ¹QÏ
```
[Try it online!](https://tio.run/##MzBNTDJM/f/f5/BiF8/cw22HdgYe7v//39iIywgA "05AB1E – Try It Online")
**Explanation**
```
L           # range [1 ... input_1]
 ã          # cartesian product with itself
  D         # duplicate
   Im       # raise each to the power of input_2
     Æ      # reduce each pair by subtraction
      ¹QÏ   # keep only values in the first copy which are true in this copy
```
[Answer]
# [MATL](https://github.com/lmendo/MATL), 11 bytes
```
t:i^&-!=&fh
```
[Try it online!](https://tio.run/##y00syfn/v8QqM05NV9FWLS3j/39jIy4jAA) Or [verify all test cases](https://tio.run/##y00syfmf8L/EKjNOTVfRVi0t47@6rq6ueoRLyH9TAy4jLmMjIGHOZcxlZmbKZQYA).
### Explanation
```
t     % Implicit input: M. Duplicate
:     % Range [1 2 ... M]
i     % Input: n
^     % Power, element-wise. Gives [1^n 2^n ... M^n]
&-    % Matrix of pairwise differences (size n×n)
!     % Transpose. Needed so the two numbers in each pair are sorted as required
=     % Is equal? Element-wise. Gives true for entries of the matrix equal to M
&f    % Row and column indices of true entries
h     % Concatenate horizontally. Implicit display
```
[Answer]
# [APL (Dyalog)](https://www.dyalog.com/), 21 bytes
```
{o/⍨⍵=-/¨⍺*⍨¨o←,⍳2⍴⍵}
```
[Try it online!](https://tio.run/##SyzI0U2pTMzJT///P@1R24TqfP1HvSse9W611dU/BKR3aQG5h1bkA6V0HvVuNnrUuwUoWfv/v5FCmoKxEZcxkDLnMgOSZmamAA "APL (Dyalog Unicode) – Try It Online")
Left argument is `n`.
[Answer]
# [Python 2](https://docs.python.org/2/), 65 bytes
```
lambda k,n:[(j%k,j/k)for j in range(k,k*k)if(j%k)**n-(j/k)**n==k]
```
[Try it online!](https://tio.run/##LY3BDoIwEETP@hVzaeiSJSoIGBL8EfWA0SJUF4Jw8OsrDZz2JfNmtv@Nr05iZ1Di6t7V5/6oYFmKi26V5XZnyXQDWjSCoZL6qS3b0FJjfE5hKJH20gxlaW/Oy7MCId/QecqIiaHT/QpJvELOSPzNstnJPJ0OjCMV200/NDIiUMnEUBOiM9Q3gFqGGWZ5QO4P "Python 2 – Try It Online")
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 10 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
*Iċ³
ṗ2çÐf
```
A full program taking `i`, and `n` which prints out the pairs of `[b,a]` with an empty output when there are none.
**[Try it online!](https://tio.run/##AR4A4f9qZWxsef//KknEi8KzCuG5lzLDp8OQZv///zMy/zI "Jelly – Try It Online")**
### How?
```
*Iċ³ - Link 1, isValid?: pair of +ve integers, [b,a]; +ve integer, n
*    - exponentiate             -> [b^n,a^n]
 I   - incremental differences  -> [a^n-b^n]
   ³ - program's third argument -> i
  ċ  - count occurrences        -> 1 if a^n-b^n == i, otherwise 0
ṗ2çÐf - Main link: +ve integer i, +ve integer n
ṗ2    - second Cartesian power = [[1,1],[1,2],...,[1,i],[2,1],...,[2,i],...,[i,i]]
   Ðf - filter keeping if:
  ç   -   call last link (1) as a dyad (left = one of the pairs, right = n)
      - implicit print of Jelly representation of the list
```
[Answer]
# JavaScript (ES7), 64 bytes
A recursive function taking input in currying syntax `(n)(p)`. Returns a space-separated list of pairs of integers, or an empty string if no solution exists. Uses the same algorithm as [user202729's Python answer](https://codegolf.stackexchange.com/a/153198/58563).
```
n=>p=>(g=x=>x--?((y=(x**p+n)**(1/p))%1?[]:[y,x]+' ')+g(x):[])(n)
```
Or **60 bytes** with 0-terminated, encapsulated arrays:
```
n=>p=>(g=x=>x--&&((y=(x**p+n)**(1/p))%1?g(x):[y,x,g(x)]))(n)
```
This would output `[ 9, 7, [ 6, 2, 0 ] ]` for **f(32)(2)**.
### Test cases
```
let f =
n=>p=>(g=x=>x--?((y=(x**p+n)**(1/p))%1?[]:[y,x]+' ')+g(x):[])(n)
console.log(f(50)(2))
console.log(f(32)(2))
console.log(f(7)(3))
console.log(f(665)(6))
```
[Answer]
# [Pyth](https://pyth.readthedocs.io), 14 bytes
```
f/.+^RvzTQ^SQ2
```
**[Try it here!](https://pyth.herokuapp.com/?code=f%2F.%2B%5ERvzTQ%5ESQ2&input=75%0A2&debug=0), [Alternative!](https://pyth.herokuapp.com/?code=f%2F.%2B%5ERvzTQ%2aSQS&input=75%0A2&debug=0)**
[Answer]
# [Python 3](https://docs.python.org/3/), 71 bytes
Thanks Mr.Xcoder for saving some bytes!
```
lambda x,n:[(a,b)for b in range(1,x)for a in[(b**n+x)**(1/n)]if a%1==0]
```
[Try it online!](https://tio.run/##VcjBCsIwDADQu1@Ri5DUgOvKKgj9krlDilYLmo2yQ/36KoKgx/eW53qb1bUUTu0uj3gWqKzHEYUjpblAhKxQRK8XtFw/Je8aMRqju0rGoN0rTTmBbG0I3dSWknXFhEPHPdHmS9f/8cDuR94P7InaCw "Python 3 – Try It Online")
---
# [Python 3](https://docs.python.org/3/), 69 bytes
```
lambda x,n:[(a,b)for b in range(1,x)for a in range(x)if a**n-b**n==x]
```
[Try it online!](https://tio.run/##K6gsycjPM/6fZhvzPycxNyklUaFCJ88qWiNRJ0kzLb9IIUkhM0@hKDEvPVXDUKcCLJSIEKrQzExTSNTSytNNAhK2thWx/wuKMvNKNNI0TA10jDQ1uWBcYyMUrrmOMRLPzMxUx0xT8z8A "Python 3 – Try It Online")
Use totallyhuman's x^2 brute force approach actually saves bytes.
[Answer]
# [Octave](https://www.gnu.org/software/octave/), 80 bytes
```
function r=f(n,p)[X Y]=meshgrid(1:n,1:n);r=[X(:) Y(:)](X(:).^p-Y(:).^p==n,:);end
```
[Try it online!](https://tio.run/##LcrBDoIwEATQu1@xx91kNQJSTEn/g4ZgYqBVDi6kor9f28hhZt5hlnG7f12M/iPjNi8CwXgUXqnvwA7m5d7PR5gnLLRwCrXB9B1qAptqwMzTbT3a/xojrKl1MkWPTc1Q0sFjfd5RlTsahiqvUumjsq4Fw4XiDw)
[Answer]
# [Perl 6](http://perl6.org/), 45 bytes
```
->\k,\n{grep * **n-* **n==k,flat 1..k X 1..k}
```
[Try it online!](https://tio.run/##K0gtyjH7n1upoJamYPtf1y4mWycmrzq9KLVAQUtBSytPF0za2mbrpOUkligY6ullK0SAqdr/aflFCjamBgpGdjoKNsZGENpcwRhEWRgqmNgp6NopRKtk6yio5MUqVCsUJ1YqKEG4Co/aJilUa6QpQLiaej6ZxSV6BUDH1Cop1P4HAA "Perl 6 – Try It Online")
]