Find permutation of n which is divisible by 3 but not divisible by 6 | C ++ program to find permutation of n which is divisible by 3 but not divisible by 6 ; Function to find the permutation ; length of integer ; if integer is even ; return odd integer ; rotate integer ; return - 1 in case no required permutation exists ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findPermutation ( int n ) { int len = ceil ( log10 ( n ) ) ; for ( int i = 0 ; i < len ; i ++ ) { if ( n % 2 != 0 ) { return n ; } else { n = ( n / 10 ) + ( n % 10 ) * pow ( 10 , len - i - 1 ) ; continue ; } } return -1 ; } int main ( ) { int n = 132 ; cout << findPermutation ( n ) ; return 0 ; }