Check whether a given number is Polydivisible or Not | CPP program to check whether a number is polydivisible or not ; function to check polydivisible number ; digit extraction of input number ; store the digits in an array ; n contains first i digits ; n should be divisible by i ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; void check_polydivisible ( int n ) { int N = n ; vector < int > digit ; while ( n > 0 ) { digit . push_back ( n % 10 ) ; n /= 10 ; } reverse ( digit . begin ( ) , digit . end ( ) ) ; bool flag = true ; n = digit [ 0 ] ; for ( int i = 1 ; i < digit . size ( ) ; i ++ ) { n = n * 10 + digit [ i ] ; if ( n % ( i + 1 ) != 0 ) { flag = false ; break ; } } if ( flag ) cout << N << " ▁ is ▁ Polydivisible ▁ number . " ; else cout << N << " ▁ is ▁ Not ▁ Polydivisible ▁ number . " ; } int main ( ) { int n = 345654 ; check_polydivisible ( n ) ; }