-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFLAGS.java
More file actions
87 lines (49 loc) · 1.08 KB
/
FLAGS.java
File metadata and controls
87 lines (49 loc) · 1.08 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
class Ideone{
//https://www.codechef.com/problems/FLAGS
public static Scanner scn = new Scanner(System.in);
public static void main (String[] args) throws java.lang.Exception{
int T = scn.nextInt();
while(T-- > 0){
long N = scn.nextInt();
long ans = 0;
//pattern 1
long p1 = 0;
if(N >= 2){
//all different
p1 += N * (N-1) * (N-2);
//1st and 3rd part same
p1 += N * (N-1);
}
ans += p1;
//pattern 2
//same as pattern1
long p2 = p1;
ans += p2;
//pattern 3
long p3 = 0;
if(N >= 3){
//all different
p3 += N * (N-1) * (N-2);
}
ans += p3;
//pattern 4
long p4 = 0;
if(N >= 3){
//all different
p4 += N * (N-1) * (N-2) * (N-3);
//part 3 and 4 same
p4 += N * (N-1) * (N-2);
}
ans += p4;
//pattern 5
//same as pattern 4
long p5 = p4;
ans += p5;
System.out.println("" + ans);
}
}
}