Instead of using Subset generation using bit-masking, i used loops (not very efficient but just wanted to try) to get the different subsets but the something is wrong can someone help?
What is wrong with my code?
where is the code ?
send the link
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;
cin>>t;
while(t–){
long long n;
cin>>n;
long long ans = 0;
long long arr[] = {2, 3, 5, 7, 11, 13, 17, 19};
// Single
for(int i = 0; i < 8 ; i++)
ans += (n/arr[i]);
// Double
for(int i = 0 ; i < 8 ; i++)
for(int j = i+1 ; j < 8 ; j++)
ans -= (n/(arr[i]*arr[j]));
// Triple
for(int i = 0 ; i < 8 ; i++)
for(int j = i+1 ; j < 8 ; j++)
for(int k = j+1 ; k < 8 ; k++)
ans += (n/(arr[i] * arr[j] * arr[k]));
// four
for(int i = 0 ; i < 8 ; i++)
for(int j = i+1 ; j < 8 ; j++)
for(int k = j+1 ; k < 8 ; k++)
for(int l = k+1; l < 8 ; l++)
ans -= (n/(arr[i] * arr[j] * arr[k] * arr[l]));
//five
for(int i = 0 ; i < 8 ; i++)
for(int j = i+1 ; j < 8 ; j++)
for(int k = j+1 ; k < 8 ; k++)
for(int l = k+1; l < 8 ; l++)
for(int m = l+1; m < 8; m++)
ans += (n/(arr[i] * arr[j] * arr[k] * arr[l] * arr[m]));
//six
for(int i = 0 ; i < 8 ; i++)
for(int j = i+1 ; j < 8 ; j++)
for(int k = j+1 ; k < 8 ; k++)
for(int l = k+1; l < 8 ; l++)
for(int m = l+1; m < 8; m++)
for(int n = m+1; n < 8; n++)
ans -= (n/(arr[i] * arr[j] * arr[k] * arr[l] * arr[m] * arr[n]));
//seven
for(int i = 0 ; i < 8 ; i++)
for(int j = i+1 ; j < 8 ; j++)
for(int k = j+1 ; k < 8 ; k++)
for(int l = k+1; l < 8 ; l++)
for(int m = l+1; m < 8; m++)
for(int n = m+1; n < 8; n++)
for(int o = n+1; o < 8; o++)
ans += (n/(arr[i] * arr[j] * arr[k] * arr[l] * arr[m] * arr[n] * arr[o]));
//all
ans -= (n/(arr[0] * arr[1] * arr[2] * arr[3] * arr[4] * arr[5] * arr[6] * arr[7]));
cout<<ans<<endl;
}
return 0;
}
why are you dividing n with a[i]???
Any logic?
Because thats how we calculate the number of numbers divisible by the prime number. a[i] stores one of the prime numbers lesser than 20.
Nevermind i solved it using subset method but this method should work as well. Dont really know why it didnt.
if you are so confident on this method,
then dont leave it and try to find the bugs.
if its wrong its wrong.