Number obtained by reducing sum of digits of 2 N into a single digit | C ++ program for the above approach ; Function to find the number obtained by reducing sum of digits of 2 ^ N into a single digit ; Stores answers for different values of N ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int findNumber ( int N ) { int ans [ 6 ] = { 1 , 2 , 4 , 8 , 7 , 5 } ; return ans [ N % 6 ] ; } int main ( ) { int N = 6 ; cout << findNumber ( N ) << endl ; return 0 ; }