Sum of all second largest divisors after splitting a number into one or more parts | Function to find a number is prime or not ; If there is any divisor ; Function to find the sum of all second largest divisor after splitting a number into one or more parts ; If number is prime ; If n is even ; If the number is odd ; If N - 2 is prime ; There exists 3 primes x1 , x2 , x3 such that x1 + x2 + x3 = n ; Driver code ; Function call
function prime ( n ) { if ( n == 1 ) return false ; for ( let i = 2 ; i * i <= n ; ++ i ) if ( n % i == 0 ) return false ; return true ; } function Min_Sum ( n ) { if ( prime ( n ) ) return 1 ; if ( n % 2 == 0 ) return 2 ; else { if ( prime ( n - 2 ) ) return 2 ; else return 3 ; } } let n = 27 ; document . write ( Min_Sum ( n ) ) ;