Sum of all possible triplet products from given ranges | Java program to implement the above approach ; Function to find the sum of all possible triplet products ( i * j * k ) ; Stores sum required sum ; Iterate over all possible values of i ; Iterate over all possible values of j ; Iterate over all possible values of k ; Stores the product of ( i * j * k ) ; Update sum ; Driver Code
import java . util . * ; class GFG { static int M = 1000000007 ; static int findTripleSum ( int A , int B , int C ) { int sum = 0 ; for ( int i = 1 ; i <= A ; i ++ ) { for ( int j = 1 ; j <= B ; j ++ ) { for ( int k = 1 ; k <= C ; k ++ ) { int prod = ( ( ( i % M ) * ( j % M ) ) % M * ( k % M ) ) % M ; sum = ( sum + prod ) % M ; } } } return sum ; } public static void main ( String args [ ] ) { int A = 10 ; int B = 100 ; int C = 1000 ; System . out . println ( findTripleSum ( A , B , C ) ) ; } }