2 // 2 test cases
14 // 14 days
3 // 3 numbers. Every number(N) means that per N day(s) have a hartal.
3 // Per 3 day(s) have a hartal.
4
8
|
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
Days |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Su |
Mo |
Tu |
We |
Th |
Fr |
Sa |
Su |
Mo |
Tu |
We |
Th |
Fr |
Sa |
Party 1 |
|
|
x |
|
|
x |
|
|
x |
|
|
x |
|
|
Party 2 |
|
|
|
x |
|
|
|
x |
|
|
|
x |
|
|
Party 3 |
|
|
|
|
|
|
|
x |
|
|
|
|
|
|
Hartals |
|
|
1 |
2 |
|
|
|
3 |
4 |
|
|
5 |
|
|
----
package uva10050;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
/**
*
* @author awesq
*/
public class UVa10050 {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try (Scanner sc = new Scanner(System.in)) {
int cases = sc.nextInt();
final int START_DAY = 1;
while (cases-- > 0) {
int days = sc.nextInt();
int parties = sc.nextInt(), sum = 0;
ArrayList hartalAl = new ArrayList();
WeekHartalPair[] isHartalDay = new WeekHartalPair[days + 1];// index 0 isn't used.
for (int i = START_DAY; i <= days; i++) {
isHartalDay[i] = new WeekHartalPair((i - 1) % 7, false); // 0 represents Sunday and so on.
}
// Read hartals.
while (parties-- > 0) {
hartalAl.add(sc.nextInt());
}
// Set hartal day.
for (Object hartal : hartalAl) {
for (int i = 1; i <= days; i++) {
if (i % ((int) hartal) == 0 && isHartalDay[i].dayOfWeek != 5 && isHartalDay[i].dayOfWeek != 6) { // Friday and Saturday doesn't work.
isHartalDay[i].isHartal = true;
}
}
}
for (WeekHartalPair whp : isHartalDay) {
if (whp != null) { // index == 0 is null
if (whp.isHartal == true) {
sum++;
}
}
}
System.out.println("" + sum);
}
} catch (Exception e) {
}
}
}
class WeekHartalPair {
public int dayOfWeek;
public boolean isHartal;
public WeekHartalPair(int dayOfWeek, boolean isHartal) {
this.dayOfWeek = dayOfWeek;
this.isHartal = isHartal;
}
}