集训第六周 数学概念与方法 数论 筛素数 H题
Description
问题是这样的:一个十进制数,如果是素数,而且它的各位数字和也是素数,则称之为“美素数”,如29,本身是素数,而且2+9 = 11也是素数,所以它是美素数。
给定一个区间,你能计算出这个区间内有多少个美素数吗?
Input
接下来共T行,每行输入两个整数L,R(1<= L <= R <= 1000000),表示区间的左值和右值。
Output
每组数据占一行,具体输出格式参见样例。
Sample Input
1 100
2 2
3 19
Sample Output
Case #2: 1
Case #3: 4
#include"iostream"
#include"cstdio"
#include"cstring"
using namespace std;
const int maxn=+;
int ans[maxn+];
int noprime[maxn+]; void Prime()
{
memset(noprime,,sizeof(noprime));
noprime[]=;
noprime[]=;
for(int i=;i<=maxn;i++)
if(!(noprime[i]))
for(int j=i*;j<=maxn;j+=i)
noprime[j]=;
} int sum(int a)
{
int s=;
while(a/)
{
s+=a%;
a/=;
}
s+=a;
return s;
} int main()
{
Prime();
int T,ca=;
ans[]=;
ans[]=;
for(int i=;i<=maxn;i++)
{
if((!noprime[i])&&(!noprime[sum(i)]))
ans[i]=ans[i-]+; //这样写便于快速查询
else
ans[i]=ans[i-];
}
cin>>T;
while(T--)
{
int l,r;
cin>>l>>r;
printf("Case #%d: %d\n",ca++,ans[r]-ans[l-]);
}
return ;
}
集训第六周 数学概念与方法 数论 筛素数 H题的更多相关文章
- 集训第六周 数学概念与方法 数论 线性方程 I题
Description The Sky is Sprite. The Birds is Fly in the Sky. The Wind is Wonderful. Blew Throw the Tr ...
- 集训第六周 数学概念与方法 概率 F题
Submit Status Description Sometimes some mathematical results are hard to believe. One of the common ...
- 集训第六周 数学概念与方法 计数 排列 L题
Description 大家常常感慨,要做好一件事情真的不容易,确实,失败比成功容易多了! 做好“一件”事情尚且不易,若想永远成功而总从不失败,那更是难上加难了,就像花钱总是比挣钱容易的道理一样. 话 ...
- 集训第六周 数学概念与方法 J题 数论,质因数分解
Description Tomorrow is contest day, Are you all ready? We have been training for 45 days, and all g ...
- 集训第六周 数学概念与方法 概率 N题
N - 概率 Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Submit Status ...
- 集训第六周 数学概念与方法 概率 数论 最大公约数 G题
Description There is a hill with n holes around. The holes are signed from 0 to n-1. A rabbit must h ...
- 集训第六周 数学概念与方法 UVA 11181 条件概率
http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=18546 题意:有n个人会去超市,其中只有r个人会买东西,每个人独自买东西的概 ...
- 集训第六周 数学概念与方法 UVA 11722 几何概型
---恢复内容开始--- http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=31471 题意,两辆火车,分别会在[t1,t2],[ ...
- 集训第六周 古典概型 期望 D题 Discovering Gold 期望
Description You are in a cave, a long cave! The cave can be represented by a 1 x N grid. Each cell o ...
随机推荐
- Robot Framework问题汇总...不断更新中
在实际使用Robot Framework工具过程中,难免会遇到一些问题, 我们将会一一记录下来,以便后来者碰到类似的问题能够快速解决! 安装类问题: ========================= ...
- SQL 初级教程学习(五)
1.DEFAULT 约束用于向列中插入默认值. CREATE TABLE Orders(Id_O int NOT NULL,OrderNo int NOT NULL,Id_P int,OrderDat ...
- ACM_棋棋棋棋棋(规律题)
棋棋棋棋棋 Time Limit: 2000/1000ms (Java/Others) Problem Description: 在遥远的K次元空间,一年一度的GDUFE-GAME又开始了.每年的GD ...
- 大小写 unix and windows
如果你没有使用工具, 只是sqlplus对大小写不敏感. 如果你要给sql传递参数,且在windows下面就不需要考虑.如果是aix系统,最好写一样.
- [转]Azure 表存储和 Windows Azure SQL Database - 比较与对照
本文转自:https://msdn.microsoft.com/library/azure/jj553018 更新时间: 2014年10月 作者:Valery Mizonov 和 Seth Manhe ...
- HTML5的音频播放和视频播放
1.音频播放 audio(音频) html5提供了播放音频文件的标准 <audio src="anli.mp3" controls="controls" ...
- 单例模式及php实现
单例模式: 单例模式(Singleton Pattern):单例模式确保某一个类只有一个实例,而且自行实例化并向整个系统提供这个实例,这个类称为单例类,它提供全局访问的方法. 单例模式的要点有三个:一 ...
- html----有关图像
这一节内容可概括为:网页上插入图片,调整图片大小,使用缩略图链接至大图. 图片的三种格式:jpeg png gif 照片.复杂图像使用jpeg,单色图像.logo.几何图形使用png以及 ...
- QT入门学习2
QT获取窗口几何布局有2类函数: 1.包含框架:x().y().frameGemetry().pos().move()... 2.不包含框架:geometry().width().height().w ...
- Quartz2D知识点聚合案例
Quartz2D知识点聚合 基本 //画图片 UIImage *image = [UIImage imageNamed:@"阿狸头像"]; [image drawInRect:re ...