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<max> is_prime(0);
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;
	
	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_prime(l))cout<<s[r]-s[l]+1<<endl;
		else cout<<s[r]-s[l];
	}
	
	
	
}


Compiler output:
a.cc:8:11: error: template argument 1 is invalid
    8 | bitset<max> is_prime(0);
      |           ^
a.cc:9:1: error: expected unqualified-id before 'for'
    9 | for(int i=2;i<=max;i++)is_prime.set(i);
      | ^~~
a.cc:9:13: error: 'i' does not name a type
    9 | for(int i=2;i<=max;i++)is_prime.set(i);
      |             ^
a.cc:9:20: error: 'i' does not name a type
    9 | for(int i=2;i<=max;i++)is_prime.set(i);
      |                    ^
a.cc:10:1: error: expected unqualified-id before 'for'
   10 | for(int i=2;i<=max;i++){
      | ^~~
a.cc:10:13: error: 'i' does not name a type
   10 | for(int i=2;i<=max;i++){
      |             ^
a.cc:10:20: error: 'i' does not name a type
   10 | for(int i=2;i<=max;i++){
      |                    ^
a.cc: In function 'int is_2017(int)':
a.cc:23:20: error: 'is_prime' cannot be used as a function
   23 |         if(is_prime(x1)&&is_prime(x2))return 1;
      |            ~~~~~~~~^~~~
a.cc:23:34: error: 'is_prime' cannot be used as a function
   23 |         if(is_prime(x1)&&is_prime(x2))return 1;
      |                          ~~~~~~~~^~~~
a.cc: In function 'int main()':
a.cc:33:23: error: reference to 'max' is ambiguous
   33 |         vector<int> s(max);
      |                       ^~~
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:35:23: error: reference to 'max' is ambiguous
   35 |         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:36:28: error: 'is_prime' cannot be used as a function
   36 |                 if(is_prime(i))count++;
      |                    ~~~~~~~~^~~
a.cc:43:28: error: 'is_prime' cannot be used as a function
   43 |                 if(is_prime(l))cout<<s[r]-s[l]+1<<endl;
      |                    ~~~~~~~~^~~
a.cc: In function 'int is_2017(int)':
a.cc:21:11: warning: control reaches end of non-void function [-Wreturn-type]
   21 |         x2=(x+1)/2+1;
      |         ~~^~~~~~~~~~