Advertisement
Saleh127

Light oj(LO) 1117

May 10th, 2021
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define test int t; cin>>t; for(int cs=1;cs<=t;cs++)
  5.  
  6. ll lcm(ll a,ll b)
  7. {
  8. return (a*b)/__gcd(a,b);
  9. }
  10.  
  11. int main()
  12. {
  13. ios_base::sync_with_stdio(0);
  14. cin.tie(0);cout.tie(0);
  15.  
  16. test
  17. {
  18. ll n,m,i,j,k,l,ans;
  19.  
  20. cin>>n>>m;
  21. vector<ll>x(m+5);
  22.  
  23. for(i=0;i<m;i++) cin>>x[i];
  24.  
  25. ans=n;
  26.  
  27. for(i=1;i<(1<<m);i++)
  28. {
  29. bitset<32>check = bitset<32>(i);
  30.  
  31. k=1;
  32. l=0;
  33. for(j=0;j<m;j++)
  34. {
  35. //if(i && (1<<j))
  36.  
  37. if(check[j]==1)
  38. {
  39. l++;
  40. k=lcm(k,x[j]);
  41. }
  42. }
  43. if(l%2) ans-=(n/k);
  44. else ans+=(n/k);
  45. }
  46.  
  47. cout<<"Case "<<cs<<": "<<ans<<endl;
  48.  
  49. ///AUBUC = A+B+C-A∩B-A∩C-B∩C+A∩B∩C
  50. ///so ans= n - A - B - C + A∩B + A∩C + B∩C - A∩B∩C
  51. }
  52.  
  53. return 0;
  54. }
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement