湖南大学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基础之equals() 和 hashCode()
equals()是Object中的一个方法: public boolean equals(Object obj) { return (this == obj); } 在Object中equals()方 ...
- 第4章-Vue.js 交互及实例的生命周期
一.学习目标 了解实例生命周期的过程 理解钩子函数的作用 掌握Vue.js过滤器的使用方法 (重点) 能够使用网络请求进行前后端交互 (重点.难点) 二.交互的基本概念 2.1.前端和后端的概念 说明 ...
- 《用Apache HttpClient实现URL重定向》
作者:chszs,转载需注明.博客主页:http://blog.csdn.net/chszs 很多网站都使用了URL重定向技术,把一个原始请求从一个位置路由到另一个位置.原因可能是多方面的,比如域名转 ...
- python标准数据类型 Bytes
预备知识: bin(): """ Return the binary representation of an integer. >>> bin(279 ...
- 解决tomcat占用8080端口问题图文详解
相信很多朋友都遇到过这样的问题吧,tomcat死机了,重启eclipse之后,发现 Several ports (8080, 8009) required by Tomcat v6.0 Server ...
- [洛谷P2747] [USACO5.4]周游加拿大Canada Tour
洛谷题目链接:[USACO5.4]周游加拿大Canada Tour 题目描述 你赢得了一场航空公司举办的比赛,奖品是一张加拿大环游机票.旅行在这家航空公司开放的最西边的城市开始,然后一直自西向东旅行, ...
- 分享一个彻底冻结对象的函数——来自阮一峰老师的《ECMAScript 6 入门》
var constantize = (obj) => { Object.freeze(obj); Object.keys(obj).forEach( (key, i) => { if ( ...
- Eng1—English daily notes
English daily notes 2015年 4月 Phrases 1. As a side note #作为附注,顺便说句题外话,和by the way意思相近,例句: @1:As a sid ...
- HttpUtility.UrlEncode与Server.UrlEncode()转码区别
在对URL进行编码时,该用哪一个?这两都使用上有什么区别吗?测试: string file="文件上(传)篇.doc";string Server_UrlEncode=Server ...
- 固定bottom,页面其它可滑动实现方案
利用flex布局, <html> <body> <div class='container'> <div class='content'></di ...