File tree Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Expand file tree Collapse file tree 1 file changed +54
-0
lines changed Original file line number Diff line number Diff line change 1+ #include  < bits/stdc++.h> 
2+ using  namespace  std ; 
3+ 
4+ int  t, l, r;
5+ vector<int > v;
6+ 
7+ int  s (int  r) {
8+ 	return  upper_bound (v.begin (), v.end (), r)-v.begin ();
9+ }
10+ 
11+ int  solve () {
12+ 	cin >> l >> r;
13+ 	return  (l<=1 )+(l<=8 &&8 <=r)+(l<=4 &&4 <=r)+s (r)-s (l-1 )+s (r/4 )-s ((l+3 )/4 -1 )+r/2 -(l-1 )/2 -r/4 +(l-1 )/4 ;
14+ }
15+ 
16+ struct  segmentedsieve  {
17+ 	void  ac (int  n, auto  f) {
18+ 		int  s=1 ;
19+ 		while (s*s<n)
20+ 			++s;
21+ 		vector<int > c (s+1 ), v;
22+ 		for (int  i=2 ; i<=s; ++i) {
23+ 			if (c[i])
24+ 				continue ;
25+ 			f (i);
26+ 			v.push_back (i);
27+ 			for (int  j=i*i; j<=s; j+=i)
28+ 				c[j]=1 ;
29+ 		}
30+ 		for (int  i1=s+1 , i2=2 *s; i1<=n; i1+=s, i2+=s) {
31+ 			c=vector<int >(s);
32+ 			for (int  p : v)
33+ 				for (int  j=(i1+p-1 )/p; j*p<=i2; ++j)
34+ 					c[j*p-i1]=1 ;
35+ 			for (int  j=i1; j<=i2; ++j)
36+ 				if (!c[j-i1]&&j<=n)
37+ 					f (j);
38+ 		}
39+ 	}
40+ } ss;
41+ 
42+ int  main () {
43+ 	ios::sync_with_stdio (0 );
44+ 	cin.tie (0 );
45+ 
46+ 	ss.ac (1e9 , [](const  int  &i) {
47+ 		v.push_back (i);
48+ 	});
49+ 	v.erase (v.begin ());
50+ 
51+ 	cin >> t;
52+ 	for (int  i=1 ; i<=t; ++i)
53+ 		cout << " Case #"   << i << " : "   << solve () << " \n "  ;
54+ }
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments