// Java implementation of the approach 
class GFG { 
  
    // Function to return the factorial of n 
    static int factorial(int n) 
    { 
        int f = 1; 
        for (int i = 1; i <= n; i++) { 
            f *= i; 
        } 
        return f; 
    } 
  
    // Function to return the sum of 
    // factorials of the array elements 
    static int sumFactorial(int[] arr, int n) 
    { 
  
        // To store the required sum 
        int s = 0; 
        for (int i = 0; i < n; i++) { 
  
            // Add factorial of all the elements 
            s += factorial(arr[i]); 
        } 
        return s; 
    } 
  
    // Driver Code 
    public static void main(String[] args) 
    { 
        int[] arr = { 7, 3, 5, 4, 8 }; 
        int n = arr.length; 
        System.out.println(sumFactorial(arr, n)); 
    } 
} 
