Ultraviolet A 1434-YAPTCHA
Question Link
Question: Find the answer to the formula in the question
Ideas:
When 3?K+ 7 when it is not a prime number, then (3?K+ 6 )! (Because we can certainly find two factors to multiply)
Therefore, the original formula is 0.
When 3?K+ When 7 is a prime number, according to Wilson's theorem, (3?K+ 6 )! + 1) % (3?K+ 7) = 0, so the original formula can be converted to [x-(x-1)] = 1
Therefore, if the problem is converted to determining whether 3 * k + 7 is a prime number, it is easy to prepare the prime number table and then pre-process the answer.
Code:
# Include
# Include
Const long N = 1000005; bool ispri [N * 3]; int ans [N], t, n; int main () {for (long I = 2; I <N * 3; I ++) {if (ispri [I]) continue; for (long j = I * I; j <N * 3; j + = I) ispri [j] = true;} for (int I = 2; I <N; I ++) ans [I] = ans [I-1] + (! Ispri [3 * I + 7]); scanf ("% d", & t); while (t --) {scanf ("% d", & n ); printf ("% d \ n", ans [n]);} return 0 ;}