diff --git a/SequenceFunc.class b/SequenceFunc.class new file mode 100644 index 0000000..6529355 Binary files /dev/null and b/SequenceFunc.class differ diff --git a/SequenceFunc.java b/SequenceFunc.java new file mode 100644 index 0000000..128864a --- /dev/null +++ b/SequenceFunc.java @@ -0,0 +1,43 @@ +import java.util.Arrays; +import java.util.Scanner; + +/** + * SequenceFunc + */ +public class SequenceFunc { + private static final int MOD = 1000000007; + + public static void main(String[] args) { + Scanner scan = new Scanner(System.in); + System.out.println("Please enter the number of elements: "); + int n = scan.nextInt(); + System.out.println("Please enter the elements of the Array"); + int[] arr = new int[n]; + for (int i = 0; i < n; i++) { + arr[i] = scan.nextInt(); + } + System.out.println("The array has the following elements: "); + for (int x : arr) { + System.out.print(x + "\t"); + + } + // to store the last result + + // let's create a temporary array + + long result = 0; + int[] temp = new int[n]; + + for (int i = 1; i <= n; ++i) { + System.arraycopy(arr, 0, temp, 0, i); + Arrays.sort(temp, 0, i); + long fi = 0; + for (int j = 0; j < i; j++) { + fi = (fi + (long) (j + 1) * temp[j]) % MOD; + } + result = (result + fi) % MOD; + } + System.out.println(result); + scan.close(); + } +}