Sum of all the prime divisors of a number | Java program to find prime divisors of all numbers from 1 to n ; function to find prime divisors of all numbers from 1 to n ; if the number is prime ; add this prime to all it 's multiples ; Driver code
import java . io . * ; import java . util . * ; class GFG { static int Sum ( int N ) { int SumOfPrimeDivisors [ ] = new int [ N + 1 ] ; for ( int i = 2 ; i <= N ; ++ i ) { if ( SumOfPrimeDivisors [ i ] == 0 ) { for ( int j = i ; j <= N ; j += i ) { SumOfPrimeDivisors [ j ] += i ; } } } return SumOfPrimeDivisors [ N ] ; } public static void main ( String args [ ] ) { int N = 60 ; System . out . print ( " Sum ▁ of ▁ prime ▁ " + " divisors ▁ of ▁ 60 ▁ is ▁ " + Sum ( N ) + "NEW_LINE"); } }