UVa 10852 - Less Prime

Summary
Pretty straightforward. Do as the question asks.

Explanation
Bruteforce should be good enough. One shortcut to note is that $$n - ( p * x )$$ is maximized when p is 1.

Input
5 4399 614 8201 101 7048

Output
2203 311 4111 53 3527