Pair Sum
Time limit1sMemory limit128 MB
This is a straightforward simulation task where numbers in each test case are used to enumerate pairs. For each input n, all pairs of distinct natural numbers with sum n are printed in lexicographic order. Because n is at most 12, iterating all possible a and b values directly works. Implemented with simple loops, this problem is a typical warm-up exercise.
- Level
Easy1 of 10
- Topics
- Simulation, Brute force, Implementation
- Solved
- No attempts yet
Problem
Given a natural number with , write a program that finds every pair of two distinct natural numbers whose sum is .
Each pair has the form , where the two numbers must be different (for example, and is not a valid pair) and the first number must always be smaller than the second one ().
Print the pairs in lexicographic order, comparing by the smaller number (the first number) of each pair. For example, comes before .
Input
The first line contains the number of test cases (). Each of the next lines contains one natural number ().
Output
For each test case, first print Pairs for n: (where n is the actual value). Then, after a single space, print the pairs whose sum is in lexicographic order, separated by , (a comma and a space). Each pair is printed as a b, its two numbers separated by a single space. If there is no pair that sums to , print nothing after Pairs for n:.