Find a permutation of 2 N numbers such that the result of given expression is exactly 2 K | C ++ program to find the required permutation of first 2 * N natural numbers ; Function to find the required permutation of first 2 * N natural numbers ; Iterate in blocks of 2 ; We need more increments , so print in reverse order ; We have enough increments , so print in same order ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void printPermutation ( int n , int k ) { for ( int i = 1 ; i <= n ; i ++ ) { int x = 2 * i - 1 ; int y = 2 * i ; if ( i <= k ) cout << y << " ▁ " << x << " ▁ " ; else cout << x << " ▁ " << y << " ▁ " ; } } int main ( ) { int n = 2 , k = 1 ; printPermutation ( n , k ) ; return 0 ; }