Question link ~~>
Question recognition:This is an idea question. During the competition, I did the D question directly, but the dizzy result of processing the coordinates was not AC at the end.
Solution:
Because only the prime number, so ~ We only need to consider the prime number, which requires the screening of prime numbers. We can add the multiples of a prime number while screening the prime number, you only need to record a certain number of records when you input them.
Code:
# Include <iostream> # include <sstream> # include <map> # include <cmath> # include <fstream> # include <queue> # include <vector> # include <sstream> # include <cstring> # include <cstdio> # include <stack> # include <bitset> # include <ctime> # include <string> # include <iomanip> # include <algorithm> using namespace STD; # define int long intconst int INF = 0x3f3f3f; const double ESP = 0.0000000001; const double Pi = ACOs (-1.0); const I NT mod = 1000000007; const int my = 100 + 5; const int MX = 10000000 + 5; int Max, n, m; bool isprime [MX]; int sum [MX], num [MX]; void Init () // number of records simultaneously recorded by the screening method {memset (isprime, false, sizeof (isprime); memset (sum, 0, sizeof (SUM); For (INT I = 2; I <= max; ++ I) {sum [I] + = sum [I-1]; If (! Isprime [I]) {sum [I] + = num [I]; for (Int J = I + I; j <= max; j + = I) {sum [I] + = num [J]; isprime [J] = true ;}}} int main () {int X; while (~ Scanf ("% d", & N) {memset (Num, 0, sizeof (Num); max = 0; For (INT I = 0; I <N; ++ I) {scanf ("% d", & X); num [x] ++; // number of records max = max (max, x );} init (); scanf ("% d", & M); int le, RT; For (INT I = 0; I <m; ++ I) {scanf ("% d", & Le, & RT); If (RT> MAX) RT = max; If (Le> MAX) cout <"0" <Endl; else cout <sum [RT]-sum [le-1] <Endl ;}} return 0 ;}
Codeforces 385 C Bear and prime numbers