Submission #1927578


Source Code Expand

Copy
#include <bits/stdc++.h>

using namespace std;

int main(void) {
	const int N = 100001;
	vector<bool> sieve(N, true);
	sieve[0] = false;
	sieve[1] = false;
	for(int i = 2; i < N; ++i) {
		for(int j = 2; i * j < N; ++j) {
			sieve[i * j] = false;
		}
	}
	vector<int> imos;//imos[i] = \sum_{0 <= k <= i, sieve[k] == true} 1
	imos.push_back(0);
	for(int i = 1; i < N; ++i) {
		if(sieve[i] && sieve[(i + 1) / 2]) {
			imos.push_back(imos.back() + 1);
		} else {
			imos.push_back(imos.back());
		}
	}
	int Q;
	cin >> Q;
	for(int i = 0; i < Q; ++i) {
		int l, r;
		cin >> l >> r;
		cout << (imos[r] - imos[l - 1]) << '\n';
	}
	return 0;
}

Submission Info

Submission Time
Task D - 2017-like Number
User waidotto
Language C++14 (GCC 5.4.1)
Score 400
Code Size 668 Byte
Status AC
Exec Time 224 ms
Memory 1148 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 10
Set Name Test Cases
Sample sample_01.txt, sample_02.txt, sample_03.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, sample_01.txt, sample_02.txt, sample_03.txt
Case Name Status Exec Time Memory
01.txt AC 222 ms 1148 KB
02.txt AC 222 ms 1148 KB
03.txt AC 218 ms 1148 KB
04.txt AC 219 ms 1148 KB
05.txt AC 211 ms 1148 KB
06.txt AC 224 ms 1148 KB
07.txt AC 221 ms 1020 KB
sample_01.txt AC 3 ms 896 KB
sample_02.txt AC 3 ms 896 KB
sample_03.txt AC 3 ms 896 KB