Submission #2545638
Source Code Expand
#include <bits/stdc++.h> using namespace std; bool is_prime(long long n) { if (n < 2 or n > 2 and n % 2 == 0) return false; for (long long i = 3; i * i <= n; i += 2) if(n % i == 0) return false; return true; } signed main() { cin.tie(0); ios::sync_with_stdio(false); vector<bool> b(1e5 + 10, false); for (int i = 3; i < 1e5; i += 2) { if (is_prime(i) and is_prime((i + 1) / 2)) b[i] = true; } vector<int> csum(1e5 + 10, 0); for (int i = 3; i < 1e5 + 10; i += 2) { csum[i] = csum[i - 2] + b[i]; } int q; cin >> q; vector<int> l(q), r(q); for (int i = 0; i < q; i++) cin >> l[i] >> r[i]; for (int i = 0; i < q; i++) { cout << csum[r[i]] - csum[max(l[i] - 2, 0)] << '\n'; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 2017-like Number |
User | risujiroh |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 747 Byte |
Status | AC |
Exec Time | 39 ms |
Memory | 1792 KB |
Judge Result
Set Name | Sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 400 / 400 | ||||
Status |
|
|
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 | 39 ms | 1792 KB |
02.txt | AC | 39 ms | 1792 KB |
03.txt | AC | 39 ms | 1792 KB |
04.txt | AC | 39 ms | 1792 KB |
05.txt | AC | 36 ms | 1792 KB |
06.txt | AC | 38 ms | 1792 KB |
07.txt | AC | 39 ms | 1664 KB |
sample_01.txt | AC | 16 ms | 640 KB |
sample_02.txt | AC | 16 ms | 640 KB |
sample_03.txt | AC | 16 ms | 640 KB |