湖南大学ACM程序设计新生杯大赛(同步赛)D - Number
题目描述
输入描述:
The input will consist of a integer n.
输出描述:
You should output how many Shuaishuai numbers in [1...n]
输入
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的更多相关文章
- 湖南大学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 ...
- 湖南大学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 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)L - Liao Han
题目描述 Small koala special love LiaoHan (of course is very handsome boys), one day she saw N (N<1e1 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)B - Build
题目描述 In country A, some roads are to be built to connect the cities.However, due to limited funds, ...
- 湖南大学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 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)E - Permutation
题目描述 A mod-dot product between two arrays with length n produce a new array with length n. If array ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)H - Yuanyuan Long and His Ballons
题目描述 Yuanyuan Long is a dragon like this picture? I don’t know, ...
- 湖南大学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 ...
- 湖南大学ACM程序设计新生杯大赛(同步赛)C - Do you like Banana ?
题目描述 Two endpoints of two line segments on a plane are given to determine whether the two segments a ...
随机推荐
- java面试梳理
自己整理的有关java面试过的问题,有错的请矫正. 1, Spring的核心思想 控制反转和面向切面的编程 2,Spring的核心模块 反向控制与依赖注入.Bean配置以及加载 3,Scope是什么 ...
- 怎样在hibernate的HQL语句中使用mysql 的自定义函数?
问题:怎样在hibernate中使用mysql的函数? 1.hibernate支持原生态的sql语句查询,使用session.createSQLQuery()创建查询对象: 2.怎样在hql中使用my ...
- CS46 C 枚举二分
给你n*2个数其中n个数是原数减去了X值的数.问你满足条件的X值和原来的n个数.注意X为正整数. X should be positive,没0的 思路很简单,一个数必定会对应一个数,那么枚举一个数和 ...
- HDU6130 签到题 打表
LINK 题意:给出一个描述自身的数列,求出第n项 思路:看了很久题目才看懂..每个值其实是描述一个分组中的个数,把两个数列对照一下就可以了,那么一个指针扫,同时向尾部加数,构造个数组就行了.其实很水 ...
- ⑥ 设计模式的艺术-06.建造者(Builder)模式
场景 我们要建造一个复杂的产品.比如:神州飞船,Iphone.这个复杂的产品的创建.有这样一个问题需要处理: 装配这些子组件是不是有个步骤问题? 实际开发中,我们所需要的对象构建时,也非常复杂,有很多 ...
- 【BZOJ】1706: [usaco2007 Nov]relays 奶牛接力跑
[题意]给定m条边的无向图,起点s,终点t,要求找出s到t恰好经过n条边的最短路径.n<=10^6,m<=100. [算法]floyd+矩阵快速幂 [题解] 先对点离散化,得到点数N. 对 ...
- iOS7下滑动返回与ScrollView共存二三事
[转载请注明出处] = =不是整篇复制就算注明出处了亲... iOS7下滑动返回与ScrollView共存二三事 [前情回顾] 去年的时候,写了这篇帖子iOS7滑动返回.文中提到,对于多页面结构的应用 ...
- python初步学习-异常
异常 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在python无法正常处理程序时就会发生一个异常. 异常是python对象,表示一个错误. 当python脚本 ...
- linux网络配置完全解析
概述:熟悉了windows下面的网络配置,对linux下的网络配置缺未必了解透彻.熟练掌握linux下的网络配置原理,能帮助我们更容易掌握网络传输原理:同时具备一些网络连接不通对应问题的排查能力.文本 ...
- linux device tree源代码解析--转
//Based on Linux v3.14 source code Linux设备树机制(Device Tree) 一.描述 ARM Device Tree起源于OpenFirmware (OF), ...