Changchun University fourteenth Programming Contest (reproduce season) H

H .Arithmetic Sequence

Topic links: https://ac.nowcoder.com/acm/contest/912/H

topic


Campaign hand the number of small r most like to do the kinds of questions the number of columns is the big question, and every can get out.

You may not believe, but in fact he found a conclusion: As long as the number of columns, whether it is to give general term or recursion formula, no matter how complex the definition, can be into an arithmetic sequence. In this way, as long as he mastered arithmetic sequence, he can make any number of columns subject.

Arithmetic sequence is a sequence. In the arithmetic sequence, the difference between any adjacent two equal, this difference is called tolerance. For example, the number of columns 3,5,7,9,11,13, ⋯ is an arithmetic sequence. In this series, the second term from the difference between the preceding thereto are each equal to 2, i.e. 2 tolerance.

Various formulas known arithmetic sequence r is small: if a first term of arithmetic sequence labeled a1, standard tolerance is d, then the expression of such difference in the number of n column item is

an = a1 + (n-1 ) d

like between any two of the difference number sequence relation

an = am + (n-m ) d

and to Sn, the first key a1, the last item an, tolerance d, item number n, while the available

Sn = a1 + a2 + a3 + ⋯ + an = Σn-1i = 0 ( a1 + id) = n (a1 + an) 2 = n [2a1 + (n-1) d] 2

why he is so skilled it? Because of the small r in this formula a child found. In his third year, his teacher asked the students to do exercises from 1 to 100. Small r soon discovered the law of series, got the answer in 5050 using the above formula. So small r later when writing your textbooks, often written as a formula of arithmetic sequence and multiplied by the number of items and is equal to its first term and last term divided by 2.

Incidentally, when r is small formulas demonstrated above, use of forgery own law, assuming again that do first, for the world praiseworthy:

proband n = 1, this equation holds: the left side of the equation = a1, Eq. the right = a1 + a12 = a1 (It should be noted at this point are the first item and the last item A1), equal on both sides, is proved.

Further assume that the equation holds when n = k, there Sk = (a1 + ak) k2 = [2a1 + (k-1) d] k2.

Now show n = k + 1 The formula was established:

of Sk +. 1 = of Sk + AK +. 1 = (2a1 + (K-. 1) D) K2 + A1 + KD

= 2a1k + 2a1 + K2D + KD2 = (2a1 + KD) (k + 1) 2 = ( a1 + ak + 1) (k + 1) 2,

as ak + 1 = a1 + kd, therefore, proved.

See here, you could not help but admire the issue: Why does r so strong it?

However, strong as small r, bothered to a trivial calculation. Now you gave a small number r X, you come up with a required arithmetic sequence such that a

Sn = a1 + a2 + a3 + ⋯ + an = Σn-1i = 0 (a1 + id) = n (a1 + an) 2 = X
input description:

enter a number X, have the meaning described in the subject.

Int input guarantee range [-231~231-1] X

inside.

Description Output:

output two rows, a first row output positive integer n, represents the number of column length you will be given. Note that n is not too large, otherwise it will cause the output overrun, time-out or run-time error.

Number of columns in the second row of output in line with requirements of the subject, separated by a space between each number, meaning see subject description

of all the output range of the number required in the int, or as a wrong answer.

Example 1
Input
6
Output
. 3
1 2. 3
Example 2
Input
49
Output
. 7
1. 7. 3. 5. 11. 9 13 is

Thinking

Arithmetic sequence is as long as can be determined is odd or even, odd output two n / 2 can, even output n / 2, N- (n / 2) can, in fact, the easiest way is to the number of output on the line, the number of columns may be configured a number of arithmetic sequence.

 

#include<bits/stdc++.h>
using namespace std;
int main()
{
 
  int n;
  cin>>n;
  cout<<2<<endl;
  if(n%2==0)
      cout<<n/2<<' '<<n/2<<endl;
  else
      cout<<n/2<<' '<<n-(n/2)<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Vampire6/p/10992445.html