MODULO 10power9+7
This commit is contained in:
parent
5b38218d7a
commit
b9b9b18218
BIN
SequenceFunc.class
Normal file
BIN
SequenceFunc.class
Normal file
Binary file not shown.
43
SequenceFunc.java
Normal file
43
SequenceFunc.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user