From b9b9b182183b6b12d0e8adac288543591cc76c92 Mon Sep 17 00:00:00 2001 From: dadgam3er Date: Wed, 23 Oct 2024 18:41:22 -0400 Subject: [PATCH] MODULO 10power9+7 --- SequenceFunc.class | Bin 0 -> 1735 bytes SequenceFunc.java | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 SequenceFunc.class create mode 100644 SequenceFunc.java diff --git a/SequenceFunc.class b/SequenceFunc.class new file mode 100644 index 0000000000000000000000000000000000000000..6529355a265c778fc9b3f0c221d41210addb94f9 GIT binary patch literal 1735 zcmaJ>&2Jk;6#q@U_SlFI7i#Ll%j%q<5G?s;0pf$SExkFn{^DX5^>mlGjHC<@AuxDd9?H3 zA%F>dq@xWH4$VLmF^0}naZ}_R;a< zxUQ@vprf6`FmM0|pNdji_XAmBXtP}gb1L+-y`1G%>p>}~Nl_{2;OJEOyBK;i`j4l|sXbENQPTDpO(rGpijcI%ZTT6)*g(vcO?`{QXH zDIDQ=#y}tX8G4%7TEa2#stWEX@Vn5$;t+J(yflW`2c5Av<5IiS;;6knKEeh1#Z9gdZMW^Bl*!MVVS)cT?j|8OR{ZaJVAYWYKfW zBDi7)E41q zXjBao)#8HZ1%6Ny)oB^5c*}lA3~%cwVV>h1)x!mbp>XcPF4^u)Z%yVJkQ!~B6y?CH zQA56LZOE=+Bj_dJE<4g6n)1B0dbO~ZTZ`r?$NBZD+{e6?@@|`3M`<@iQ8-S?4rC#Y zcc~mKK`ph^TTpa_?@OO!kuKsMZu>#z_<&*H|4r!~YVgA##^}ug7>?jPE|4tJt_>II zqZvVr{;!j!pClt09lj6tP3SO5e{~GHvH#^RB@Zt5oA z#6U7`>e|P*Q!!H?y={v_c;&`ed_$*Dza_O~yrIxGI4QO$T~gadfgqk!?AxH&uTs%K zT-#xwhaT%*9Hh6a14HP<2)gJ7ccMTiMS5x9hY6dcN7u1N<-CQX_>`D*NasJ%O#h55e!(y-%5(~vwdpPTuHY)|bXvVf;66m^A7huOQ2+n{ literal 0 HcmV?d00001 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(); + } +}