[Problem Description] Certain integer can be decomposed into a number and the form of consecutive integers, for example,
15 = 1 + 2 + 3 + 4 + 5
15 = 4 + 5 + 6
15 = 7 + 8
to a certain integer not broken down into consecutive integers and, for example: 16
[a] in the form of input integer N (N <= 10000)
[All] exploded output form combinations corresponding to an integer N, if there is no combination of decomposition, the output NONE.
Sample input] [
15
[] sample output
. 1 2. 5. 4. 3
. 4. 5. 6
. 7. 8
[Sample input]
16
[output sample]
NONE
[] Example Description ascending smallest integer for each output in the decomposition of each decomposition per line, a space (each of the last row to leave a space) between each number; if there is no combination of decomposition, the output NONE
#include<iostream> #include<vector> using namespace std; int main () { int x; CIN >> X; // needs to determine the value of int In Flag = 0 ; // decided whether or not the tag into a combination Vector < int > divNumber; // declare the vector used to store a value added per cycle for ( int n-= . 1 ; n-<X; n-++) // from 1 -> x-1 iterates { int SUM = 0 ; // computing the vector as the number of and memory for ( int I = n-; I <X; ++ i ) { divNumber.push_back(i); SUM = SUM + I; IF (SUM == X) // number satisfying the condition stored { for ( int K = 0 ; K <divNumber.size (); K ++) // number of output access { cout << divNumber[k] << " "; } flag = 1; cout << endl; } the else IF (SUM> X) // stored and the number of large number ratio determination, the access time is not satisfied { divNumber.clear(); } } } if(flag == 0){ cout << "NONE" << endl; } }
Personal summary :
About application of the standard library vector.