-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDivisibleByK.java
More file actions
80 lines (67 loc) · 1.84 KB
/
DivisibleByK.java
File metadata and controls
80 lines (67 loc) · 1.84 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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class DivisibleByK {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int a[] = new int[n];
int diff[]=new int[n];
int sum=0;
HashMap<Integer,Integer> map=new HashMap<Integer,Integer>(n);
for(int a_i=0; a_i < n; a_i++){
a[a_i] = in.nextInt();
}
// diff=diffArray(a, k);
//
// for(int i=0;i<n;i++){
// if(!map.containsKey(diff[i])){
// map.put(diff[i],freq(a,diff[i]));
// }
// }
for(Integer i:map.keySet()){
sum=sum+(Integer) map.get(i);
}
sum=0;
//System.out.println("Sum is"+sum);
ArrayList list=createComboSum(a);
// System.out.println("size of c"+list.size());
for(int c=0; c<list.size();c++){
System.out.println(list.get(c));
if(c%k==0){
sum=sum+1;
}
}
//System.out.println(sum);
}
// static int[] diffArray(int a[],int k){
// int diff[]=new int[a.length];
// for(int count=0;count<a.length;count++){
// diff[count]=Math.abs(k-a[count]);
// System.out.println(diff[count]);
// }
//
// return diff;
// }
// static int freq(int[] a,int num){
// int count=0;
// for(int i=0;i<a.length;i++){
// if(num==a[i]){
// count=count+1;
// }
// }
// return count;
// }
static ArrayList createComboSum(int a[]){
ArrayList arr=new ArrayList();
for(int i=0;i<a.length;i++){
for(int j=1;j<(a.length-i);j++){
arr.add(a[i]+a[j]);
}
}
return arr;
}
}