UVA 1434-yaptcha
Topic links
Test instructions: Find out the answer to the formula in the question
Ideas:
When 3? k + 7 Non-prime time, then (3? ) k + 6 )! (Two factors must be found to multiply)
So the original is 0
When 3? k + 7 As a prime number, according to the Wilson theorem,((3?k+6)!+1)%(3?k+7)==0, so the primitive can be converted to [x-(x-1)] = 1
So the question turns to just to infer that 3 * k + 7 is not a prime number, then it is very good to do, preprocessing the prime table, and then preprocess the answer can be
Code:
#include <stdio.h> #include <string.h>const long long N = 1000005;bool ispri[n * 3];int ans[n], T, N;int Main () {for (long long i = 2; i < N * 3; i++) {if (Ispri[i]) continue;for (long 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);p rintf ("%d\n", Ans[n]); } return 0;}
UVA 1434-yaptcha (number theory)