text: Ways to write N as sum of two or more positive integers | Set | C # implementation of above approach ; Function to find the number of partitions of N ; Base case ; Driver code
code: using System ; class GFG { static long partitions ( int n ) { long [ ] p = new long [ n + 1 ] ; p [ 0 ] = 1 ; for ( int i = 1 ; i <= n ; ++ i ) { int k = 1 ; while ( ( k * ( 3 * k - 1 ) ) / 2 <= i ) { p [ i ] += ( k % 2 != 0 ? 1 : - 1 ) * p [ i - ( k * ( 3 * k - 1 ) ) / 2 ] ; if ( k > 0 ) { k *= - 1 ; } else { k = 1 - k ; } } } return p [ n ] ; } public static void Main ( String [ ] args ) { int N = 20 ; Console . WriteLine ( partitions ( N ) ) ; } }