A prospector catalogs 2n ingots pulled from a mine, numbered consecutively from 1 to 2n in the order they were smelted. Every ingot bearing an odd number is stacked into the Left Vault; every ingot bearing an even number is stacked into the Right Vault. The value of each ingot is simply its smelting number. Given n, determine the greatest common divisor of the total value stacked in the Left Vault and the total value stacked in the Right Vault.
A single line containing the integer n.
A single integer: the greatest common divisor of the Left Vault's total and the Right Vault's total.
Example 1
Input
1
Expected
1
Explanation
With n=1 the ingots are 1 and 2. The Left Vault holds only ingot 1 (total 1); the Right Vault holds only ingot 2 (total 2). gcd(1, 2) = 1.
Example 2
Input
4
Expected
4
Explanation
With n=4 the ingots are 1 through 8. The Left Vault holds 1, 3, 5, 7 (total 16); the Right Vault holds 2, 4, 6, 8 (total 20). gcd(16, 20) = 4.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →