UVA 10050 Java

import java.util.*;
import static java.lang.System.*;

public class main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int cases = sc.nextInt();
    for(int t = 0; t < cases; t++)
    {
    	int n = sc.nextInt();
    	int h = sc.nextInt();
    	int[] party = new int[h];
    	for(int i = 0; i < h; i++)
    		party[i] = sc.nextInt();
    	int count = 0;
    	for(int i = 1; i < n + 1; i++)
    	{
    		boolean flag = false;
    		for(int j = 0; j < h; j++)
    			if(i % party[j] == 0)
    				flag = true;
    		if(flag && i % 7 != 0 && i % 7 != 6)
    			count++;
    	}
    	System.out.println(count);
    }
  }
};

留言

這個網誌中的熱門文章

C# 井字遊戲