集训第六周 数学概念与方法 数论 筛素数 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 ... 
随机推荐
- Golang 入门 : 理解并发与并行
			Golang 的语法和运行时直接内置了对并发的支持.Golang 里的并发指的是能让某个函数独立于其他函数运行的能力.当一个函数创建为 goroutine 时,Golang 会将其视为一个独立的工作单 ... 
- 在xampp集成环境下使用 thinkphp 连接oracle
			今天搞了大半天,终于成功了. 1. 首先需要让xampp支持oracle,直接按这个网页上说的做就行.http://nimal.info/blog/2009/activate-oracle-on-xa ... 
- flask框架基础入门一
			首先:flask是一个基于Werkzeug,Jinja2的一个python的微服务框架. 安装flask框架: pip install flask 一个最小的最简单的flask应用: from fla ... 
- [USACO 2012 Jan Silver] Bale Share【DP】
			传送门:http://www.usaco.org/index.php?page=viewproblem2&cpid=107 没想到太不应该了,真的不应该啊! f[i][j][k]表示前i个包, ... 
- 桥接模式和php实现
			桥接模式(Bridge Pattern): 将抽象部分与它的实现部分分离,使它们都可以独立地变化.它是一种对象结构型模式,又称为柄体(Handle and Body)模式或接口(Interface)模 ... 
- Python 设计模式--简单工厂模式
			简单工厂模式(Factory Pattern)是一种创建型的设计模式,像工厂一样根据要求生产对象实例. 特点:根据不同的条件,工厂实例化出合适的对象. <大话设计模式>中实例:四则运算计算 ... 
- CSS3实现边框线条动画特效
			<div class="box-line"></div> CSS代码 .box-line, .box-line::before, .box-line::af ... 
- 仿微信右滑关闭Activity
			SwipeBackLayout 1.AS添加依赖 compile 'me.imid.swipebacklayout.lib:library:1.0.0' eclipse 想办法下载库工程,以库工程形式 ... 
- iOS Programming Web Services and UIWebView
			iOS Programming Web Services and UIWebView The work is divided into two parts. The first is connecti ... 
- iOS programming  UITableView and UITableViewController
			iOS programming UITableView and UITableViewController A UITableView displays a single column of dat ... 
