mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-27 19:56:28 +00:00
P1865 A % B Problem
R42016947
This commit is contained in:
parent
fa47505d1d
commit
4d0737896e
39
problem/P1865/P1865.cpp
Normal file
39
problem/P1865/P1865.cpp
Normal file
@ -0,0 +1,39 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int ans[10000005];
|
||||
|
||||
bool isPrime(int x) {
|
||||
if (x == 1) {
|
||||
return false;
|
||||
}
|
||||
for (int i = 2; i * i <= x; i++) {
|
||||
if (x % i == 0) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
for (int i = 1; i <= m; i++) {
|
||||
ans[i] = ans[i - 1];
|
||||
if (isPrime(i)) {
|
||||
ans[i]++;
|
||||
}
|
||||
}
|
||||
while (n--) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
if (l > m || r > m || l < 1 || r < 1) {
|
||||
cout << "Crossing the line" << endl;
|
||||
}
|
||||
else {
|
||||
cout << ans[r] - ans[l - 1] << endl;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user