Sha 10050 hartals (Strike index, brute force enumeration .)

Source: Internet
Author: User





Hartals

A social research organization has determined a simple set of parameters to simulate the behavior of the political parties of our country. one of the parameters is a positive integerh (called the hartal parameter) that denotes the average number of days between two successive hartals (strikes) called by the corresponding party. though the parameter is far too simple to be flawless, it can still be used to forecast the damages caused by hartals. the following example will give you a clear idea:


Consider three political parties. assume H1 = 3, H2 = 4 and h3 = 8 Where Hi is the hartal parameter for party I (I = 1, 2, 3 ). now, we will simulate the behavior of these three parties for n = 14 days. one must always start the simulation on a Sunday and assume that there will be no hartals on weekly holidays (on Fridays and Saturdays ).


  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    


The simulation above shows that there will be exactly 5 hartals (on days 3, 4, 8, 9 and 12) in 14 days. there will be no hartal on day 6 since it is a Friday. hence we lose 5 working days in 2 weeks.

In this problem, given the hartal parameters for several political parties and the value of N, your job is to determine the number of working days we lose in those N days.

Input

The first line of the input consists of a single integer t giving the number of test cases to follow.

The first line of each test case contains an integer N () giving the number of days over which the simulation must be run. the next line contains another integer p () representing the number of political parties in this case. the ith of the next p lines contains a positive integer HI (which will never be a multiple of 7) Giving thehartal parameter for party I ().

Output

For each test case in the input output the number of working days we lose. Each output must be on a separate line.

Sample Input
2143348100412152540
Sample output
515
Question:

It is useless to give you a continuous day of rest on Saturday and Friday. I will give you another P organization. Each organization will give you a number, indicating that the political party will strike at the multiples of this number. Ask the total number of days of the strike in these days.

Solution:

Brute force enumeration. Note that multiple organizations may strike on the same day. This is only one day.


Code:

#include<iostream>#include<cstdio>#include<cstring>using namespace std;int main(){    int t,num,p[110];    bool visited[5000];    cin>>t;    while(t--){        int cnt=0,nump;        cin>>num>>nump;        memset(visited,false,num+1);        for(int i=0;i<nump;i++) cin>>p[i];        for(int i=0;i<nump;i++){            for(int j=1;j<=num;j++){                  if(j%p[i]==0&&j%7!=6&&j%7!=0&&!visited[j]){                    cnt++;                    visited[j]=true;                }            }        }       cout<<cnt<<endl;    }    return 0;}






Sha 10050 hartals (Strike index, brute force enumeration .)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.