题目描述

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. org.hibernate.HibernateException: getFlushMode is not valid without active transaction

    Spring & Hibernate 整合异常记录: org.hibernate.HibernateException: getFlushMode is not valid without a ...

  2. elasticsearch ik中文分词器的安装配置使用

    安装步骤  https://github.com/medcl/elasticsearch-analysis-ik 以插件形式安装: [elsearch@localhost elasticsearch- ...

  3. vim如何粘贴

    刚开始vim的学习之旅,在进行粘贴操作时遇到了麻烦. 教程上粘贴的命令是p,但我发现该命令只适用于从vim到vim的复制(p未必就仅仅局限于此,但我目前所了解到的情况如此),当我从网上复制了一段代码想 ...

  4. 机器学习-kNN-寻找最好的超参数

    一 .超参数和模型参数 超参数:在算法运行前需要决定的参数 模型参数:算法运行过程中学习的参数 - kNN算法没有模型参数- kNN算法中的k是典型的超参数 寻找好的超参数 领域知识 经验数值 实验搜 ...

  5. php的发展历史

    php最初就是为了快速构建一个web页面而迅速被大家广为接受的.它的好处是在代码中能内嵌html的代码,从而让程序员能再一个页面中同时写html代码和php代码就能生成一个web页面. 这篇文章用时间 ...

  6. perl6检测网站CMS脚本(测试代码)

    代码如下: use HTTP::UserAgent; use JSON::Tiny; my $check-url = 'www.baidu.com'; #say @*ARGS[0]; #检测命令行参数 ...

  7. python设计模式之装饰器详解(三)

    python的装饰器使用是python语言一个非常重要的部分,装饰器是程序设计模式中装饰模式的具体化,python提供了特殊的语法糖可以非常方便的实现装饰模式. 系列文章 python设计模式之单例模 ...

  8. 【Windows使用笔记】神舟笔记本的control center

    首先,神船大法好. 然后,因为我的船风扇声音有点大啊,在实验室感觉就很吵,但是它的背板温度又不是很高,所以想设置下风扇的启动. 所以需要用到神船自带的control center软件. 长这样. 应该 ...

  9. Ubuntu 17.10 用 apt 搭建 lamp 环境(精简版)

    这篇文章主要用来快速部署以 php 5.6 为主的 lamp 环境,要看详细安装包括虚拟主机配置的请参考这篇:http://www.cnblogs.com/mingc/p/7864030.html 一 ...

  10. Fedora8 U盘安装

    (一)分区 在XP下"我的电脑“管理功能,对硬盘分区,目的是从逻辑分区中拿出20G空间,分成3个盘(必须为逻辑盘): (1)512MB   用作Linux swap分区: (2)200MB  ...