how to solve this problem. please give any approach
Not So Easy Math approach
No of numbers between 1 to n which are divisible by x are [n/x]
where [] is greatest integer function.
Try to use it
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long int arr[]={2,3,5,7,11,13,17,19};
long long int t,a,len,i,j,ans;
cin>>t;
while(t–)
{
ans=0;
cin>>a;
len=(sizeof(arr)/sizeof(arr[0]));
for(i=0;i<len;i++)
{
ans += (a/arr[i]);
for(j=i+1;j<len;j++)
{
ans -= (a/(arr[i]*arr[j])) ;
}
}
cout<<ans<<"\n";
}
}
please tell me mistake
does this qstn has anything to do with bitmasking?
you have taken only pair
you have to take triplet then 4 number at a time then 5 so oon .
this is my code…which passed all test case
`#include
using namespace std;
typedef long long int ll;
int main(){
ll t;cin>>t;ll primes[] = {2,3,5,7,11,13,17,19};
while(t–){
ll n;cin>>n;
ll subsets = (1<<8)-1;ll ans=0;
for(ll i=1;i<=subsets;i++){
ll denom = 1ll;
ll sb=__builtin_popcount(i);
for(ll j=0;j<=7;j++){
if(i&(1<<j)){
denom = denom*primes[j];
}
}
ans=((sb&1)?ans+(n/denom):ans-(n/denom));
}
cout<<ans<<endl;
}
return 0;
// insta ==> krish_krush
}`