Check whether count of odd and even factors of a number are equal | C ++ solution for the above approach ; Function to check condition ; Initialize even_count and od_count ; loop runs till square root ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; #define lli  long long int NEW_LINE void isEqualFactors ( lli N ) { lli ev_count = 0 , od_count = 0 ; for ( lli i = 1 ; i <= sqrt ( N ) + 1 ; i ++ ) { if ( N % i == 0 ) { if ( i == N / i ) { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } else { if ( i % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; if ( ( N / i ) % 2 == 0 ) ev_count += 1 ; else od_count += 1 ; } } } if ( ev_count == od_count ) cout << " YES " << endl ; else cout << " NO " << endl ; } int main ( ) { lli N = 10 ; isEqualFactors ( N ) ; return 0 ; }