Check if a number exists with X divisors out of which Y are composite | C ++ program to check if a number exists having exactly X positive divisors out of which Y are composite divisors ; Count the number of times 2 divides N ; check for all possible numbers that can divide it ; if N at the end is a prime number . ; Function to check if any such number exists ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int factorize ( int N ) { int count = 0 ; int cnt = 0 ; while ( ( N % 2 ) == 0 ) { N = N / 2 ; count ++ ; } cnt = cnt + count ; for ( int i = 3 ; i <= sqrt ( N ) ; i += 2 ) { count = 0 ; while ( N % i == 0 ) { count ++ ; N = N / i ; } cnt = cnt + count ; } if ( N > 2 ) cnt = cnt + 1 ; return cnt ; } void ifNumberExists ( int X , int Y ) { int C , dsum ; C = X - Y - 1 ; dsum = factorize ( X ) ; if ( dsum >= C ) cout << " YES ▁ STRNEWLINE " ; else cout << " NO ▁ STRNEWLINE " ; } int main ( ) { int X , Y ; X = 6 ; Y = 4 ; ifNumberExists ( X , Y ) ; return 0 ; }