Sum of all second largest divisors after splitting a number into one or more parts | CPP program to find sum of all second largest divisor 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
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool prime ( int n ) { if ( n == 1 ) return false ; for ( int i = 2 ; i * i <= n ; ++ i ) if ( n % i == 0 ) return false ; return true ; } int Min_Sum ( int n ) { if ( prime ( n ) ) return 1 ; if ( n % 2 == 0 ) return 2 ; else { if ( prime ( n - 2 ) ) return 2 ; else return 3 ; } } int main ( ) { int n = 27 ; cout << Min_Sum ( n ) ; return 0 ; }