UVA 1434-yaptcha (number theory)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.