Interview Questions/Coding/Largest Pair GCD Shortcut

Largest Pair GCD Shortcut

Preview mode. Log in to edit, run, submit, and save progress.

Easy

Largest Pair GCD Shortcut

For each integer n, an audit asks for the largest possible greatest common divisor of two distinct positive integers that are not greater than n. Report only that maximum gcd value. Input Format: The first line contains t, the number of test cases. Each test case contains n. Output Format: For each test case, print the maximum possible gcd.

Examples

Example 1
Input:
1
10
Output:
5

Explanation: The pair 10 and 5 has gcd 5, and no valid pair can have a larger gcd.

Approach hint

Start with a simple approach, explain the trade-off, then move toward a cleaner or more scalable solution.

Common mistake

Skipping assumptions, edge cases, or trade-offs can make an otherwise good answer feel incomplete.

Loading...
Input
1 10
Output
5