Form a number using corner digits of powers | C ++ program to find number formed by corner digits of powers . ; Find next power by multiplying N with current power ; Store digits of Power one by one . ; Calculate carry . ; Store carry in Power array . ; Prints number formed by corner digits of powers of N . ; Storing N raised to power 0 ; Initializing empty result ; One by one compute next powers and add their corner digits . ; Call Function that store power in Power array . ; Store unit and last digits of power in res . ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void nextPower ( int N , vector < int > & power ) { int carry = 0 ; for ( int i = 0 ; i < power . size ( ) ; i ++ ) { int prod = ( power [ i ] * N ) + carry ; power [ i ] = prod % 10 ; carry = prod / 10 ; } while ( carry ) { power . push_back ( carry % 10 ) ; carry = carry / 10 ; } } void printPowerNumber ( int X , int N ) { vector < int > power ; power . push_back ( 1 ) ; vector < int > res ; for ( int i = 1 ; i <= X ; i ++ ) { nextPower ( N , power ) ; res . push_back ( power . back ( ) ) ; res . push_back ( power . front ( ) ) ; } for ( int i = 0 ; i < res . size ( ) ; i ++ ) cout << res [ i ] ; } int main ( ) { int N = 19 , X = 4 ; printPowerNumber ( X , N ) ; return 0 ; }