Submission #3413329
Source Code Expand
#include <iostream> #include <string> #include <algorithm> #include <vector> #include <map> using namespace std; typedef long long ll; #define rep(i,s,n)for(ll i=s;i<n;i++) #define repe(i,s,n)for(ll i=s;i<=n;i++) bool p[100001]; bool q[100001]; int main() { ll maxV = 100000; rep(i, 0, maxV)p[i] = true; p[0] = false; p[1] = false; for (int i = 2; i*i <= maxV; i++) { if (!p[i])continue; for (int j = 2; i*j <= maxV; j++) { if (i*j <= maxV) { p[i*j] = false; } } } rep(i, 0, maxV) { q[i] = p[i]; } rep(i, 0, maxV) { if (p[i] && p[(i + 1) / 2]) { q[i] = true; } else { q[i] = false; } } ll s[100001] = {}; rep(i, 1, maxV) { s[i] += s[i - 1] + (q[i] ? 1 : 0); } ll Q; cin >> Q; rep(i, 0, Q) { ll l, r; cin >> l >> r; cout << s[r] - s[l - 1] << endl; } return 0; }
Submission Info
Submission Time | |
---|---|
Task | D - 2017-like Number |
User | butanokakuni_d1 |
Language | C++14 (GCC 5.4.1) |
Score | 400 |
Code Size | 875 Byte |
Status | AC |
Exec Time | 222 ms |
Memory | 1664 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 | 222 ms | 1536 KB |
02.txt | AC | 213 ms | 1536 KB |
03.txt | AC | 213 ms | 1536 KB |
04.txt | AC | 214 ms | 1536 KB |
05.txt | AC | 203 ms | 1664 KB |
06.txt | AC | 207 ms | 1664 KB |
07.txt | AC | 215 ms | 1536 KB |
sample_01.txt | AC | 2 ms | 1280 KB |
sample_02.txt | AC | 2 ms | 1280 KB |
sample_03.txt | AC | 2 ms | 1280 KB |