[Huawei OD Unified Exam B Paper | 100 points] Solving Continuous Sequences (C++ Java JavaScript Python)

Huawei OD Online OJ:

Users who have already purchased this column, please private message the blogger to open an account and brush up questions online! ! !

Online OJ: brush the questions immediately

Question bank column: 2023 Huawei OD machine test (A volume + B volume) (C++JavaJSPy)

topic description

It is known that the sum of the continuous positive integer sequence {K}=K1, K2, K3...Ki is S, i=N (0<S<100000, 0<N<100000), find this sequence K.

enter description

The input contains two parameters, 1) continuous positive integer sequence and S, 2) the number N of numbers in the sequence.

output description

If there is a solution, output the sequence K, if there is no solution, output -1.

Example

enter 525 6
output 85 86 87 88 89 90
illustrate none

topic analysis

Problem solving method:
This problem can be solved using the double pointer method. The double pointer method is an efficient algorithm for finding a specific condition in an array or sequence. In this problem, we use two pointers leftand rightto denote the start and end position of the current continuous sequence of integers. By moving these two pointers, we can do in O(n)

Guess you like

Origin blog.csdn.net/shangyanaf/article/details/132642644