Skip to content

Commit 3c9b123

Browse files
committedNov 11, 2021
IR
1 parent 3180cf8 commit 3c9b123

File tree

1 file changed

+54
-0
lines changed
  • CodePtit/src/main/java/Handling_File

1 file changed

+54
-0
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package Handling_File;
7+
8+
/**
9+
*
10+
* @author Admin
11+
*/
12+
import java.io.*;
13+
import java.util.*;
14+
public class snt {
15+
public static int check(int n){
16+
if(n<2){
17+
return 0;
18+
}
19+
for(int i = 2; i<= Math.sqrt(n); i++){
20+
if(n%i == 0){
21+
return 0;
22+
}
23+
}
24+
return 1;
25+
}
26+
27+
public static void main(String[] args) throws FileNotFoundException, IOException, ClassNotFoundException {
28+
ObjectInputStream din = new ObjectInputStream(new FileInputStream("DATA1.in"));
29+
ObjectInputStream din1 = new ObjectInputStream(new FileInputStream("DATA2.in"));
30+
TreeSet<Integer> ts = new TreeSet<>();
31+
TreeSet<Integer> ts1 = new TreeSet<>();
32+
ArrayList<Integer> arr = (ArrayList<Integer>) din.readObject();
33+
ArrayList<Integer> arr2 = (ArrayList<Integer>) din1.readObject();
34+
35+
for(Integer i : arr){
36+
if(check(i)== 1){
37+
ts.add(i);
38+
}
39+
}
40+
41+
for(Integer i : arr2){
42+
if(check(i) == 1){
43+
ts1.add(i);
44+
}
45+
}
46+
47+
for(Integer i: ts){
48+
long tmp = 1000000 - i;
49+
if(ts1.contains(tmp) && i < tmp){
50+
System.out.println(i + " " + tmp);
51+
}
52+
}
53+
}
54+
}

0 commit comments

Comments
 (0)
Please sign in to comment.