Hunan University ACM Program Design Freshman Cup contest (synchronized race) D-number + violence __algorithm

Source: Internet
Author: User

Time limit: c/s + + 2 seconds, other languages 4 seconds
Space restrictions: C/C + + 65536K, other languages 131072K
64bit IO Format:%lld
Topic description
We define Shuaishuai-number as a number which is the sum of a prime square (squared), Prime Cube (cubic), and prime Fourth power (four times ).
The four Shuaishuai numbers are:

How many Shuaishuai numbers in [1,n]? (1<=n<=50 000 000)
Enter a description:
The input would consist of a integer n.
Output Description:
Should output how many Shuaishuai numbers in [1...N]
Example 1
Input

28
Output

1
Description

There is only one Shuaishuai number

Analysis: Prime number screen play table, violence.

#include <iostream> #include <cstdio> #include <queue> #include <cstring> #include <
Algorithm> #define LL long int using namespace STD;
const int MAXN = 2e6 + 10;
int A[MAXN];
int VIS[MAXN];
int C[MAXN];
int n;
int Len;
    void Get_prime () {len = 0;
        for (int i = 2; i < MAXN i++) {if (vis[i)) continue;
        a[len++] = i;
        for (int j = 2 * i; J < maxn; j = i) {vis[j] = 1;
    int main () {memset (Vis, 0, sizeof vis);
    memset (c, 0, sizeof C);
    scanf ("%d", &n);
    Get_prime ();
    int ans = 0;
    int cs = 0;
        for (int i = 0; i < len; i++) {int TMP1 = a[i] * a[i] * a[i] * a[i];
        if (Tmp1 > N) break;
            for (int j = 0; J < Len; j +) {int TMP2 = a[j] * a[j] * A[j] + tmp1;
            if (Tmp2 > N) break;
                for (int k = 0; k < Len; k++) {int Tmp3 = a[k] * A[k] + tmp2; if (Tmp3 <= N) {c[cs++] = Tmp3;}
            if (Tmp3 > N) break;
    }} sort (c, C + CS);
    if (c[0]) ans = 1;
    for (int i = 1; i < CS; i++) {if (C[i]!= c[i-1]) ans++;
    printf ("%d\n", ans);
return 0; }
Related Article

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.