fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. const int MAX = 30000001;
  5.  
  6. int s[MAX];
  7.  
  8. int main() {
  9. for(int c = 1; c < MAX; ++c) {
  10. for(int a = c << 1; a < MAX; a += c) {
  11. if ((a-c) == (a^c)) {
  12. s[a] += 1;
  13. }
  14. }
  15. }
  16. for(int i = 1; i < MAX; ++i) {
  17. s[i] += s[i-1];
  18. }
  19. int tt, n;
  20. scanf("%d", &tt);
  21. for(int t = 1; t <= tt; ++t) {
  22. scanf("%d", &n);
  23. printf("Case %d: %d\n", t, s[n]);
  24. }
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.85s 120640KB
stdin
2
7
20000000
stdout
Case 1: 4
Case 2: 34866117