#GL0000199. Biểu diễn bằng tổng các số liên tiếp (Consecutive Sums)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Biểu diễn bằng tổng các số liên tiếp (Consecutive Sums)
Biểu diễn bằng tổng các số liên tiếp (Consecutive Sums)
Source: Kattis
Version: Phuoc Hung OJ Extended
Problem Statement
Given positive integer , express it as a sum of at least two consecutive positive integers. If several representations exist, choose the one with the fewest summands. Output the full equation N = a + (a+1) + ... + b with every term actually listed, or print IMPOSSIBLE if none exists.
Input
A single positive integer .
Output
Print the full equation on one line, or IMPOSSIBLE.
Subtasks
-
Subtask 1 (20 points): .
-
Subtask 2 (30 points): .
-
Subtask 3 (50 points): .
Examples
Example 1
Input
10
Output
10 = 1 + 2 + 3 + 4
Explanation
The representation is the unique sum of at least two consecutive positive integers.
Example 2
Input
24
Output
24 = 7 + 8 + 9
Explanation
The shortest representation is , which has three summands. No two consecutive positive integers sum to .
Example 3
Input
8
Output
IMPOSSIBLE
Explanation
A power of two cannot be expressed as a sum of two or more consecutive positive integers.