GO Solution For UVa 10025 - The ? 1 ? 2 ? ... ? n = k problem. In this post we will see how we can solve this challenge in GoLang for UVa Online Judge.

Problem Description

Given the following formula, one can set operators ‘+’ or ‘-’ instead of each ‘?’, in order to obtain a given k

?1?2? . . .?n = k

For example: to obtain k = 12, the expression to be used will be:

  • 1 + 2 + 3 + 4 + 5 + 6 - 7 = 12

with n = 7

Input The first line is the number of test cases, follo

...

You can find the full details of the problem The ? 1 ? 2 ? ... ? n = k problem at UVa Online Judge

Sample Input

2

12

-3646397

Sample Output

7

2701

Solution: Please check the main.go snippet for the solution.

Solution originally posted at: Github by @codingsince1985