题目描述

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 <cstdio>
#include <algorithm>
using namespace std; const int maxn = 50000000;
int a[1200000 + 10];
int sz = 0, cnt = 0;
int b[1200000 + 10];
bool noprime[maxn + 10];
int n; void init() {
noprime[1] = 1;
for(int i = 2; i <= maxn; i ++) {
if(noprime[i]) continue;
for(int j = i + i; j <= maxn; j = j + i) {
noprime[j] = 1;
}
}
for(int i = 1; i * i <= maxn; i ++) {
if(noprime[i]) continue;
for(int j = 1; i * i + j * j * j <= maxn; j ++) {
if(noprime[j]) continue;
for(int k = 1; i * i + j * j * j + k * k * k * k <= maxn; k ++) {
if(noprime[k]) continue;
a[sz ++] = i * i + j * j * j + k * k * k * k;
}
}
}
sort(a, a + sz);
b[cnt ++] = a[0];
for(int i = 1; i < sz; i ++) {
if(a[i] == a[i - 1]) continue;
b[cnt ++] = a[i];
}
} int main() {
init();
while(~scanf("%d", &n)) {
int L = 0, R = cnt - 1, pos = -1;
while(L <= R) {
int mid = (L + R) / 2;
if(b[mid] <= n) pos = mid, L = mid + 1;
else R = mid - 1;
}
printf("%d\n", pos + 1);
}
return 0;
}

  

湖南大学ACM程序设计新生杯大赛(同步赛)D - Number的更多相关文章

  1. 湖南大学ACM程序设计新生杯大赛(同步赛)J - Piglet treasure hunt Series 2

    题目描述 Once there was a pig, which was very fond of treasure hunting. One day, when it woke up, it fou ...

  2. 湖南大学ACM程序设计新生杯大赛(同步赛)A - Array

    题目描述 Given an array A with length n  a[1],a[2],...,a[n] where a[i] (1<=i<=n) is positive integ ...

  3. 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han

    题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...

  4. 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build

    题目描述 In country  A, some roads are to be built to connect the cities.However, due to limited funds, ...

  5. 湖南大学ACM程序设计新生杯大赛(同步赛)I - Piglet treasure hunt Series 1

    题目描述 Once there was a pig, which was very fond of treasure hunting. The treasure hunt is risky, and ...

  6. 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation

    题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...

  7. 湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons

    题目描述 Yuanyuan Long is a dragon like this picture?                                     I don’t know, ...

  8. 湖南大学ACM程序设计新生杯大赛(同步赛)G - The heap of socks

    题目描述 BSD is a lazy boy. He doesn't want to wash his socks, but he will have a data structure called ...

  9. 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?

    题目描述 Two endpoints of two line segments on a plane are given to determine whether the two segments a ...

随机推荐

  1. UndertowServer+SpringMVC+Thymeleaf模板引擎构建轻量级的web项目

    这两周需要写一个页面来请求另一个服务中的接口,服务器采用了超轻量级的undertow,模板引擎采用的是Thymeleaf,在寻找页面资源位置这个地方难住了我.下面分享一下,这方面的代码. Spring ...

  2. 【IIS】IIS中同时满足集成模式和经典模式

    手里有一个项目--系统设置(主要功能是对系统一些字典表的设置.权限管理等功能).在VS上运行没有任何问题.可是发布到IIS上之后,报黄页. 发布后程序运行环境为: windows 7 32位 IIS为 ...

  3. 【BZOJ】3091: 城市旅行 Link-Cut Tree

    [题意]参考PoPoQQQ. 给定一棵树,每个点有一个点权,提供四种操作: 1.删除两点之间的连边 不存在边则无视 2.在两点之前连接一条边 两点已经联通则无视 3.在两点之间的路径上所有点的点权加上 ...

  4. pip install bs4安装失败

    使用管理员方式打开命令提示符框,然后pip install bs4即可安装成功:

  5. 【转载】在GitHub上管理项目

    在GitHub上管理项目 新建repository 本地目录下,在命令行里新建一个代码仓库(repository) 里面只有一个README.md 命令如下: touch README.md git ...

  6. 42.Trapping Rain Water---dp,stack,两指针

    题目链接:https://leetcode.com/problems/trapping-rain-water/description/ 题目大意:与84题做比较,在直方图中计算其蓄水能力.例子如下: ...

  7. 深入解析Mysql 主从同步延迟原理及解决方案

    MySQL的主从同步是一个很成熟的架构,优点为:①在从服务器可以执行查询工作(即我们常说的读功能),降低主服务器压力;②在从主服务器进行备份,避免备份期间影响主服务器服务;③当主服务器出现问题时,可以 ...

  8. git中如何查看一个文件的修改(更新)历史

    有些时候有些文件或文件夹被移除了, 或者更换了路径或被改名了, 想跟踪一下这个文件被修改(更新)的历史, 可以用如下命令: git log -p matser -- filename 格式是: git ...

  9. 关于boost 的smart_ptr 的使用问题

    boost 的smart_ptr 库中含有好几种智能指针,大家用的最多的应该是shared_ptr ,为啥呢?好用,不用管他啥时候会自动删除等等,而且拷贝和复制都很到位, 但实际上,这个库也有问题,连 ...

  10. nginx 查看当前的连接数

    netstat -n | awk '/^tcp/ {++S[$NF]} END {for(a in S) print a,S[a]}' https://www.cnblogs.com/lianzhil ...