湖南大学ACM程序设计新生杯大赛(同步赛) D -Number 【打表+暴力】
2017-12-24 18:35
337 查看
时间限制:C/C++ 2秒,其他语言4秒
空间限制:C/C++ 65536K,其他语言131072K
64bit IO Format: %lld
题目描述
We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), and prime fourth power(四次方).
The first four Shuaishuai numbers are:
How many Shuaishuai numbers in [1,n]? (1<=n<=50 000 000)
输入描述:
The input will consist of a integer n.
输出描述:
You should output how many Shuaishuai numbers in [1…n]
示例1
输入
28
输出
1
说明
There is only one Shuaishuai number
分析:素数筛打表,暴力。
空间限制:C/C++ 65536K,其他语言131072K
64bit IO Format: %lld
题目描述
We define Shuaishuai-Number as a number which is the sum of a prime square(平方), prime cube(立方), and prime fourth power(四次方).
The first four Shuaishuai numbers are:
How many Shuaishuai numbers in [1,n]? (1<=n<=50 000 000)
输入描述:
The input will consist of a integer n.
输出描述:
You should output how many Shuaishuai numbers in [1…n]
示例1
输入
28
输出
1
说明
There is only one Shuaishuai number
分析:素数筛打表,暴力。
#include<iostream> #include<cstdio> #include<queue> #include<cstring> #include<algorithm> #define ll long 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; }
相关文章推荐
- 湖南大学ACM程序设计新生杯大赛(同步赛)E-Permutation【打表+规律】
- 湖南大学ACM程序设计新生杯大赛(同步赛)A-Array 【证明+暴力】
- 湖南大学ACM程序设计新生杯大赛(同步赛)C-Do you like Banana ? 【几何】
- 湖南大学ACM程序设计新生杯大赛(同步赛)G-The heap of socks【排序】
- 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?
- 湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks
- 湖南大学ACM程序设计新生杯大赛(同步赛) I-Piglet treasure hunt Series 1【BFS】
- 湖南大学ACM程序设计新生杯大赛(同步赛)D - Number
- 湖南大学ACM程序设计新生杯大赛(同步赛) I-Piglet treasure hunt Series 1【BFS】
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
- 湖南大学ACM程序设计新生杯大赛(同步赛)L-Liao Han【打表规律+二分】
- 湖南大学ACM程序设计新生杯大赛(同步赛)L-Liao Han【打表规律+二分】
- 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build
- 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2
- 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array
- 湖南大学ACM程序设计新生杯大赛 - Yuanyuan Long and His Ballons(环形染色问题)
- 2017湖南大学ACM程序设计新生杯大赛 - B - Build (并查集&&贪心)
- Harmonic Number LightOJ - 1234 (暴力打表,区域保存)
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】
- 湖南大学ACM程序设计新生杯大赛(同步赛)H-Yuanyuan Long and His Ballons【公式】