Notes: Just Count the columns which has atleast one hartal. The hartal days are multiplier of hartal parameters.
#include <bits/stdc++.h>
using namespace std;
vector<int>b;
int main()
{
long long int i,j,n,su,mo,tu,we,th,fr,sr,t,h,k,l,a[10000],c,w,m,r,p,d,z;
//freopen("10050.txt","r",stdin);
//freopen("10050out.txt","w",stdout);
cin>>t;
for(i=1;i<=t;i++)
{
cin>>n;
cin>>h;
su=1,mo=2,tu=3,we=4,th=5,fr=6,sr=7;
for(l=1;l<=h;l++)
{
cin>>a[l];
}
c=0;
b.clear();
b.push_back(0);
for(l=1;l<=h;l++)
{
for(k=1;k<=n;k++)
{
d=1;
m=a[l]*k;
if(m>n)
{
break;
}
if(m<=n)
{
w=m%7;
if((w==su||w==mo||w==tu||w==we||w==th))
{
for(p=0;p<b.size();p++)
{
if(b[p]==m) //checking if the column has already hartal or not.
{
d=0;
}
}
if(d==1)
{
c++;
b.push_back(m); //this column m will not be considered again.
}
}
}
}
}
cout<<c<<endl;
}
return 0;
}
#include
ReplyDeleteusing namespace std;
int pt[5000];
int main()
{
int n,t,i,a=6,b=7,p,x,sum=0;
cin>>t;
while(t--)
{
cin >> n >> p;
a=6,b=7,sum=0;
for(i=1;i<=n;i++)
pt[i]=0;
while(p--)
{
cin>>x;
for(i=x;i<=n;i=i+x)
{
pt[i]=1;
}
}
for(i=1;i<=n;i++)
{
if((i!=a)&&(i!=b))
{
// cout << "i= " << i << " " << pt[i] << endl;
sum+=pt[i];
}
if(i==a)
{
a=a+7;
}
if(i==b)
{
b=b+7;
}
}
cout << sum << endl;
}
}