Language: C++

#include <iostream>
using namespace std;

const int max=500000;
int prime[max];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    for(int i=0; i<max; i++) prime[i]=1;
    for(int i=3; i<1000; i+=2) {
        if(!prime[i>>1]) continue;
        for(int j=(i*i)/2; j<max; j+=i) prime[j]=0;
    }
    for(int i=1; i<max; i++) prime[i]+=prime[i-1];
    int n;
    while(cin>>n) {
        cout<<prime[(n-1)/2]<<'\n';
    }
    return 0;
}



Compiler output:
a.cc:5:11: error: reference to 'max' is ambiguous
    5 | int prime[max];
      |           ^~~
In file included from /usr/include/c++/14/string:51,
                 from /usr/include/c++/14/bits/locale_classes.h:40,
                 from /usr/include/c++/14/bits/ios_base.h:41,
                 from /usr/include/c++/14/ios:44,
                 from /usr/include/c++/14/ostream:40,
                 from /usr/include/c++/14/iostream:41,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:11: note:                 'const int max'
    4 | const int max=500000;
      |           ^~~
a.cc: In function 'int main()':
a.cc:10:20: error: reference to 'max' is ambiguous
   10 |     for(int i=0; i<max; i++) prime[i]=1;
      |                    ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:11: note:                 'const int max'
    4 | const int max=500000;
      |           ^~~
a.cc:10:30: error: 'prime' was not declared in this scope
   10 |     for(int i=0; i<max; i++) prime[i]=1;
      |                              ^~~~~
a.cc:12:13: error: 'prime' was not declared in this scope
   12 |         if(!prime[i>>1]) continue;
      |             ^~~~~
a.cc:13:30: error: reference to 'max' is ambiguous
   13 |         for(int j=(i*i)/2; j<max; j+=i) prime[j]=0;
      |                              ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:11: note:                 'const int max'
    4 | const int max=500000;
      |           ^~~
a.cc:13:41: error: 'prime' was not declared in this scope
   13 |         for(int j=(i*i)/2; j<max; j+=i) prime[j]=0;
      |                                         ^~~~~
a.cc:15:20: error: reference to 'max' is ambiguous
   15 |     for(int i=1; i<max; i++) prime[i]+=prime[i-1];
      |                    ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr const _Tp& std::max(const _Tp&, const _Tp&, _Compare)'
  303 |     max(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:257:5: note:                 'template<class _Tp> constexpr const _Tp& std::max(const _Tp&, const _Tp&)'
  257 |     max(const _Tp& __a, const _Tp& __b)
      |     ^~~
a.cc:4:11: note:                 'const int max'
    4 | const int max=500000;
      |           ^~~
a.cc:15:30: error: 'prime' was not declared in this scope
   15 |     for(int i=1; i<max; i++) prime[i]+=prime[i-1];
      |                              ^~~~~
a.cc:18:15: error: 'prime' was not declared in this scope
   18 |         cout<<prime[(n-1)/2]<<'\n';
      |               ^~~~~