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; }