Divide N into K parts in the form ( X , 2 X , ... , KX ) for some value of X | C ++ program for the above approach ; Function to find the division ; Calculating value of x1 ; Print - 1 if division is not possible ; Get the first number ie x1 then successively multiply it by x1 k times by index number to get the required answer ; Driver Code ; Given N and K ; Function Call
#include <iostream> NEW_LINE using namespace std ; typedef long long int ll ; void solve ( int n , int k ) { int x1 , d ; d = k * ( k + 1 ) ; if ( ( 2 * n ) % d != 0 ) { cout << " - 1" ; return ; } x1 = 2 * n / d ; for ( int i = 1 ; i <= k ; i ++ ) { cout << x1 * i << " ▁ " ; } cout << endl ; } int main ( ) { int n = 10 , k = 4 ; solve ( n , k ) ; }