-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProblem11.java
More file actions
51 lines (34 loc) · 989 Bytes
/
Problem11.java
File metadata and controls
51 lines (34 loc) · 989 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package Problem11;
import java.util.Scanner;
public class Problem11 {
public static int[] fun(int arr[]){
int n = arr.length - 1;
int s2 = (n * (n + 1)) /2;
int s2n = (n * (n + 1)) * (2 * n + 1) / 6;
int s = 0;
int s1 = 0;
for(int i = 0; i < n; i++){
s += arr[i];
s1 += arr[i] * arr[i];
}
int val1 = s - s2;
int val2 = s1 - s2n;
val2 = val2 / val1;
int x = (val1 + val2) / 2;
int y = x - val1;
return new int[] {x , y};
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int arr[] = new int[n];
for(int i = 0; i < n; i++){
arr[i] = sc.nextInt();
}
int res[] = fun(arr);
for(int i = 0; i <res.length; i++){
System.out.print(res[i] + " ");
}
System.out.println();
}
}