Your task
Given two positive integers \$x\$ and \$d\$ (such that \$d<x\$), output the 5th term of the \$d\$th difference of the sequence \$n^x\$
Example
Let's say we are given the inputs \$x=4\$ and \$d=2\$.
First, we get the series \$n^4\$:
- \$0^4 = 0\$
- \$1^4 = 1\$
- \$2^4 = 16\$
- \$3^4 = 81\$
- ...
These are the first 10 elements:
0 1 16 81 256 625 1296 2401 4096 6561
Now we work out the differences:
0 1 16 81 256 625 1296 2401 // Original series
1 15 65 175 369 671 1105 // 1st difference
14 50 110 194 302 434 // 2nd difference
Finally, we get the 5th term (1-indexed) and output:
302
Note: this is sequence, so as long as the 5th term is somewhere in your output, it's fine.
Test cases
x d OUTPUT
4 2 302
2 1 9
3 2 30
5 3 1830
This Python program can be used to get the first three differences of any power series.