text: Weird Number | C # program to check if the number is weird or not ; code to find all the factors of the number excluding the number itself ; List to store the factors ; note that this loop runs till sqrt ( n ) ; if the value of i is a factor ; condition to check the divisor is not the number itself ; return the List ; Function to check if the number is abundant or not ; find the divisors using function ; sum all the factors ; check for abundant or not ; Function to check if the number is semi - perfect or not ; find the divisors ; sorting the List ; subset to check if no is semiperfect ; initialising 1 st column to true ; initialing 1 st row except zero position to 0 ; loop to find whether the number is semiperfect ; calculation to check if the number can be made by summation of divisors ; if not possible to make the number by any combination of divisors ; Function to check for weird or not ; Driver Code
code: using System ; using System . Collections . Generic ; class GFG { static List < int > factors ( int n ) { List < int > v = new List < int > ( ) ; v . Add ( 1 ) ; for ( int i = 2 ; i <= Math . Sqrt ( n ) ; i ++ ) { if ( n % i == 0 ) { v . Add ( i ) ; if ( n / i != i ) { v . Add ( n / i ) ; } } } return v ; } static Boolean checkAbundant ( int n ) { List < int > v ; int sum = 0 ; v = factors ( n ) ; for ( int i = 0 ; i < v . Count ; i ++ ) { sum += v [ i ] ; } if ( sum > n ) return true ; else return false ; } static Boolean checkSemiPerfect ( int n ) { List < int > v ; v = factors ( n ) ; v . Sort ( ) ; int r = v . Count ; Boolean [ , ] subset = new Boolean [ r + 1 , n + 1 ] ; for ( int i = 0 ; i <= r ; i ++ ) subset [ i , 0 ] = true ; for ( int i = 1 ; i <= n ; i ++ ) subset [ 0 , i ] = false ; for ( int i = 1 ; i <= r ; i ++ ) { for ( int j = 1 ; j <= n ; j ++ ) { if ( j < v [ i - 1 ] ) subset [ i , j ] = subset [ i - 1 , j ] ; else { subset [ i , j ] = subset [ i - 1 , j ] || subset [ i - 1 , j - v [ i - 1 ] ] ; } } } if ( ( subset [ r , n ] ) == false ) return false ; else return true ; } static Boolean checkweird ( int n ) { if ( checkAbundant ( n ) == true && checkSemiPerfect ( n ) == false ) return true ; else return false ; } public static void Main ( String [ ] args ) { int n = 70 ; if ( checkweird ( n ) ) Console . WriteLine ( " Weird ▁ Number " ) ; else Console . WriteLine ( " Not ▁ Weird ▁ Number " ) ; } }