forked from kdn251/interviews
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TheHugeOne.java
executable file
·64 lines (61 loc) · 2.43 KB
/
TheHugeOne.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/**
* Your girlfriend Marry has some problems with programming task teacher gave her. Since you have
* the great programming skills it won’t be a problem for you to help her. And certainly you don’t want
* Marry to have her time spent on this task because you were planning to go to the cinema with her this
* weekend. If you accomplish this task Marry will be very grateful and will definitely go with you to the
* cinema and maybe even more. So it’s up to you now
* That’s the task she was given:
* Number 0 ≤ M ≤ 101000 is given, and a set S of different numbers from the interval [1;12]. All
* numbers in this set are integers. Number M is said to be wonderful if it is divisible by all numbers in
* set S. Find out whether or not number M is wonderful.
* Input
* First line of input data contains number N (0 < N ≤ 2000). Then N tests follow each described on
* two lines. First line of each test case contains number M. Second line contains the number of elements
* in a set S followed by a space and the numbers in the set. Numbers of this set are separated by a space
* character.
* Output
* Output one line for each test case: ‘M - Wonderful.’, if the number is wonderful or ‘M - Simple.’
* if it is not. Replace M character with the corresponding number. Refer output data for details.
* Sample Input
* 4
* 0
* 12 1 2 3 4 5 6 7 8 9 10 11 12
* 379749833583241
* 1 11
* 3909821048582988049
* 1 7
* 10
* 3 1 2 9
* Sample Output
* 0 - Wonderful.
* 379749833583241 - Wonderful.
* 3909821048582988049 - Wonderful.
* 10 - Simple.
*/
//https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2319
import java.math.BigInteger;
import java.util.Scanner;
public class TheHugeOne {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
int numberOfTestCases = input.nextInt();
while (numberOfTestCases != 0) {
BigInteger M = input.nextBigInteger();
input.nextLine();
String[] elementsLine = input.nextLine().split(" ");
boolean found = false;
for (int i = 1; i < elementsLine.length; i++) {
BigInteger number = new BigInteger(elementsLine[i]);
if (!M.mod(number).equals(BigInteger.ZERO)) {
System.out.println(M + " - Simple.");
found = true;
break;
}
}
if (!found) {
System.out.println(M + " - Wonderful.");
}
numberOfTestCases--;
}
}
}