题目描述

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. 还不会做! 树上的gcd 树分治 UOJ33

    题目链接:http://uoj.ac/problem/33 题解链接:http://vfleaking.blog.uoj.ac/blog/38 现在感觉到了做OI的层层递进的思路的伟大之处,作为一个大 ...

  2. ④ 设计模式的艺术-10.装饰(Decorator)模式

    职责 装饰模式是在不必改变原类文件和使用继承的情况下,动态的扩展一个对象的功能.它是通过创建一个包装对象,也就是装饰来包裹真实的对象. 装饰模式是一种用于代替继承的技术,无需通过继承增加子类就能扩展对 ...

  3. 【leetcode 简单】第十三题 最大子序和

    给定一个整数数组 nums ,找到一个具有最大和的连续子数组(子数组最少包含一个元素),返回其最大和. 示例: 输入: [-2,1,-3,4,-1,2,1,-5,4], 输出: 6 解释: 连续子数组 ...

  4. E.Text Editor (Gym 101466E + 二分 + kmp)

    题目链接:http://codeforces.com/gym/101466/problem/E 题目: 题意: 给你s串和t串,一个数k,求t的最长前缀串在s串中出现次数不少于k. 思路: 一眼二分+ ...

  5. Neuroph studio 入门教程

    PERCEPTRON Perceptron is a simple two layer neural network with several neurons in input layer, and ...

  6. cin循环输入控制问题

    之前写一个简单的输入节点值自动生成链表的测试程序,发现cin的输入控制好像在VC++6.0和VS2010中不一样,特此记录. 现在有以下代码: vector<int> ivec; int ...

  7. shell 监控磁盘使用率【转】

    方案一: disks=(`df |sed 1d | awk '{print $1,$5}'|tr -d %`) len=${#disks[@]} ;i<=$len;i=i+));do ];the ...

  8. ubuntu无法获得锁 /var/lib/dpkg -open 问题

    问题: 方法: sudo rm   /var/lib/dpkg/lock 然后再安装就可以了

  9. selenium grid结构图

    调用 Selenium-Grid 的基本结构图如下: 上面是使用 selenium-grid 的一种普通方式,仅仅使用了其支持的分布式执行的功能,即当你同时需 要测试用例比较多时,可以平行的执行这些用 ...

  10. [ python ] 网络编程(2)

    黏包问题 这样一个实例 import socket import subprocess sk_server = socket.socket() # 创建 socket对象 sk_server.bind ...