-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBeakJoon1402.java
47 lines (40 loc) · 1.22 KB
/
BeakJoon1402.java
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
import java.io.IOException;
import java.util.Scanner;
import java.util.ArrayList;
public class BeakJoon1402
{
public static void main(String[] args) throws IOException
{
Scanner scan = new Scanner(System.in);
ArrayList<Integer> arr = new ArrayList<Integer>();
int testcase = scan.nextInt();
Integer Sourcevalue = Integer.parseInt(scan.next());
Integer Goalvalue = Integer.parseInt(scan.next());
int sourcevalue = Sourcevalue.intValue();
for(int i = 0; i < testcase; i++)
{
int divisor = 2;
while(sourcevalue != 1)
{
while(divisor <= sourcevalue)
{
if(sourcevalue % divisor == 0)
{
sourcevalue /= divisor;
arr.add((Integer)divisor);
}
else
divisor++;
}
}
int addResult = 0;
for(int j = 0; j < arr.size(); j++)
addResult += arr.get(j).intValue();
if(addResult == Goalvalue.intValue())
System.out.println("yes");
else
System.out.println("no");
}
scan.close();
}
}