Please if you can check my code and suggest changes
its not working
Not so easy math ( Bitmasking )
Try to solve the problem using inclusion exclusion principle
#include<bits/stdc++.h> #define ll long long using namespace std; int main() { ll t; cin>>t; int primes[] = {2, 3, 5, 7 ,11, 13, 17, 19}; ll subsets = (1<<8)-1; while(t–){ ll n; cin>> n; ll ans = 0; for(ll i =0;i<=subsets;i++){ ll setBits = __builtin_popcount(i); ll denom = 1ll; for(int j=0;j<=7;j++){ if(1& (1<<j)){ denom*= primes[j]; } } if(setBits&1){ ans += n/denom; } else{ ans-= n/denom; } } cout<< ans<<endl; } }
Save ur code on coding blocks ide and share the link.