Advertisement
Dmaxiya

数字诗意 参考代码

Mar 16th, 2025
456
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.03 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. typedef long long LL;
  5. const int maxn = 100000 + 100;
  6. int n;
  7. LL x, ans;
  8.  
  9. LL lowbit(LL x) {
  10.     return x & -x;
  11. }
  12.  
  13. void code1() {
  14.     set<int> st;
  15.     for (int i = 1; i <= 20; ++i) {
  16.         for (int j = i + 1; j <= 20; ++j) {
  17.             st.insert((i + j) * (j - i + 1) / 2);
  18.         }
  19.     }
  20.     for (int x : st) {
  21.         cout << x << endl;
  22.     }
  23. }
  24.  
  25. void code2() {
  26.     set<int> st;
  27.     for (int i = 1; i <= 200; ++i) {
  28.         st.insert(i);
  29.     }
  30.     for (int i = 1; i <= 1000; ++i) {
  31.         for (int j = i + 1; j <= 1000; ++j) {
  32.             st.erase((i + j) * (j - i + 1) / 2);
  33.         }
  34.     }
  35.     for (int x : st) {
  36.         cout << x << endl;
  37.     }
  38. }
  39.  
  40. int main() {
  41. #ifdef ExRoc
  42.     freopen("test.txt", "r", stdin);
  43. #endif
  44.     ios::sync_with_stdio(false);
  45.  
  46. //    code1();
  47. //    code2();
  48.  
  49.     cin >> n;
  50.     while (n--) {
  51.         cin >> x;
  52.         if (lowbit(x) == x) {
  53.             ++ans;
  54.         }
  55.     }
  56.     cout << ans << endl;
  57.  
  58.     return 0;
  59. }
  60.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement