hdu 4548 第六周H题(美素数)
Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u
Description
Input
Output
Sample Input
Sample Output
#include <iostream>
#include <cstdio>
using namespace std;
int a[];
int b[];
int juge(int m)
{
for(int i=; i*i<=m; i++)
if(m%i==)
return ;
return ;
}
int tongji()
{
int total=;
for(int i=; i<; i++)
{
if(juge(i))
{
a[i]=;
int f=i,num=;
while(f>)
{
num+=f%;
f/=; }
if(a[num])
total++;
}
b[i]=total; //前i个数的含有的美素数
}
}
int main()
{
tongji();
int l,r,t,k=;
cin>>t;
while(t--)
{
cin>>l>>r;
printf("Case #%d: %d\n",k++,b[r]-b[l-]); //必须是l-1,不然2 2这个案例会错
}
}
还有紫书上的Eratosthenes筛法
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int maxn=+;
int a[maxn+];
int f[maxn+];
void juge1()
{
memset(f,,sizeof(f));
for(int i=;i<=maxn;i++)
if((f[i]))
for(int j=i*;j<=maxn;j+=i)
f[j]=;
} int sum(int a)
{
int s=;
while(a/)
{
s+=a%;
a/=;
}
s+=a;
return s;
} int main()
{
juge1();
int l,r,T,k=;
for(int i=;i<=maxn;i++)
{
if((f[i])&&(f[sum(i)]))
a[i]=a[i-]+; //记录前i个数的美素数个数
else
a[i]=a[i-];
}
cin>>T;
while(T--)
{ cin>>l>>r;
printf("Case #%d: %d\n",k++,a[r]-a[l-]);
}
return ;
}
hdu 4548 第六周H题(美素数)的更多相关文章
- HDU 1465 第六周L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. ...
- HDU 2669 第六周 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the ...
- HDU 1405 第六周 J题
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all ...
- 程序设计入门—Java语言 第六周编程题 1 单词长度(4分)
第六周编程题 依照学术诚信条款,我保证此作业是本人独立完成的. 1 单词长度(4分) 题目内容: 你的程序要读入一行文本,其中以空格分隔为若干个单词,以'.'结束.你要输出这行文本中每个单词的长度.这 ...
- 数学概念——H 最美素数
H - 数论,晒素数 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- Codeforces 559A 第六周 O题
Description Gerald got a very curious hexagon for his birthday. The boy found out that all the angle ...
- 第六周 E题 期望.....
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- 第六周 N题
Description As Harry Potter series is over, Harry has no job. Since he wants to make quick money, (h ...
- HDU1465 第六周L题(错排组合数)
L - 计数,排列 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Descrip ...
随机推荐
- UVAlive3415 Guardian of Decency(最大独立集)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=34831 [思路] 二分图的最大独立集. 即在二分图中选取最多的点, ...
- How To Create a New User and Grant Permissions in MySQL
How to Create a New User Let’s start by making a new user within the MySQL shell: CREATE USER 'newus ...
- ltp工具使用配置
ltp是一个比较全的自然语言处理工具,可以用它进行分词.词性标注.语法分析等任务. ---- 准备 下载 下载ltp和ltp4j,在cmake官网下载并安装相应版本的cmake,并且下载ant. 构建 ...
- RHEL 6.4 安装svn和apache
1.安装软件包(RHEL已经按默认设置安装完成) 需要安装的.rpm软件包: postgresql-libs perl-URI subversion mod_dav_svn 2.创建svn文件夹和版本 ...
- RabbitMQ-死信(Dead Letter)
对于有异常的消息我们可以有如下做法: 记录下来再ack. nack或者reject,同时将requeue设为false. 在第2条的基础上增加死信(Dead Letter). 上边的第3个做法可以 ...
- JavaScript笔记(一),
加法函数 javascript的加法结果会有误差,在两个浮点数相加的时候会比较明显 //调用:accAdd(arg1,arg2) //返回值:arg1加上arg2的精确结果 function accA ...
- Java自动装箱和自动拆箱操作
1.Java数据类型 在介绍Java的自动装箱和拆箱之前,我们先来了解一下Java的基本数据类型. 在Java中,数据类型可以分为两大种,Primitive Type(基本类型)和Reference ...
- Android 开源项目 eoe 社区 Android 客户端(转)
本文内容 环境 开源项目 eoe 社区 Android 客户端 本文介绍 eoe 社区 Android 客户端.它是一个开源项目,功能相对简单,采用侧边菜单栏.可以学习一下.点击此处查看 GitHub ...
- Java基础知识强化之集合框架笔记04:Collection集合的基本功能测试
1. Collection集合的基本功能测试: package cn.itcast_01; import java.util.ArrayList; import java.util.Collectio ...
- HDU 5105 Math Problem
让求 f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)的最大值 这个题目讨论a和b的值,如果a==0的话,那么这个方程就变成了一个一元二次方程,直接找端点和对称轴(如果对称轴在给定的区间内 ...