Language: C++

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll=long long;

//エラトステネスでqのmaxまでの素数をbitsetにぶちこみ
int max=101010;
bitset<101010> is_prime(0);

void eratos(){
for(int i=2;i<=max;i++)is_prime.set(i);
for(int i=2;i<=max;i++){
	if(is_prime[i]){
		for(int j=i*2;j<=n;j+=i)is_prime.reset(j);	
	}
}
}


//2017数判定おｋなら1
int is_2017(int x){
	int x1,x2;
	x1=x+1;//bit配列のインデックスに
	x2=(x+1)/2+1;
	
	if(is_prime(x1)&&is_prime(x2))return 1;
	else return 0;
	
}

//Qがデカいので正攻法だとTLE
int main() {
	int q;
	cin>>q;
	
	eratos();
	
	vector<int> s(max);
	int count=0; 
	for(int i=3;i<max;i+=2){
		if(is_prime(i))count++;
		s[i]=count;
	}
	
	rep(i,q){
		int l,r;
		cin>>l>>r;
		if(is_2017(l))cout<<s[r]-s[l]+1<<endl;
		else cout<<s[r]-s[l];
	}
	
	
	
}


Compiler output:
a.cc: In function 'void eratos()':
a.cc:11:16: error: reference to 'max' is ambiguous
   11 | for(int i=2;i<=max;i++)is_prime.set(i);
      |                ^~~
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:                 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
In file included from /usr/include/c++/14/algorithm:60:
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:                 '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:7:5: note:                 'int max'
    7 | int max=101010;
      |     ^~~
a.cc:12:16: error: reference to 'max' is ambiguous
   12 | for(int i=2;i<=max;i++){
      |                ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:                 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:                 '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:7:5: note:                 'int max'
    7 | int max=101010;
      |     ^~~
a.cc:14:34: error: 'n' was not declared in this scope
   14 |                 for(int j=i*2;j<=n;j+=i)is_prime.reset(j);
      |                                  ^
a.cc: In function 'int is_2017(int)':
a.cc:26:20: error: no match for call to '(std::bitset<101010>) (int&)'
   26 |         if(is_prime(x1)&&is_prime(x2))return 1;
      |            ~~~~~~~~^~~~
a.cc:26:34: error: no match for call to '(std::bitset<101010>) (int&)'
   26 |         if(is_prime(x1)&&is_prime(x2))return 1;
      |                          ~~~~~~~~^~~~
a.cc: In function 'int main()':
a.cc:38:23: error: reference to 'max' is ambiguous
   38 |         vector<int> s(max);
      |                       ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:                 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:                 '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:7:5: note:                 'int max'
    7 | int max=101010;
      |     ^~~
a.cc:40:23: error: reference to 'max' is ambiguous
   40 |         for(int i=3;i<max;i+=2){
      |                       ^~~
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: candidates are: 'template<class _Tp, class _Compare> constexpr _Tp std::max(initializer_list<_Tp>, _Compare)'
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5706:5: note:                 'template<class _Tp> constexpr _Tp std::max(initializer_list<_Tp>)'
 5706 |     max(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:303:5: note:                 '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:7:5: note:                 'int max'
    7 | int max=101010;
      |     ^~~
a.cc:41:28: error: no match for call to '(std::bitset<101010>) (int&)'
   41 |                 if(is_prime(i))count++;
      |                    ~~~~~~~~^~~
a.cc: In function 'int is_2017(int)':
a.cc:24:11: warning: control reaches end of non-void function [-Wreturn-type]
   24 |         x2=(x+1)/2+1;
      |         ~~^~~~~~~~~~