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 ...
随机推荐
- [Locked] Palindrome Permutation I & II
Palindrome Permutation I Given a string, determine if a permutation of the string could form a palin ...
- 接口中的成员变量必须是static
首先要弄清接口的含义. 接口就是提供一种统一的'协议’, 而接口中的属性也属于'协议’中的成员.它们是公共的,静态的,最终的常量.相当于全局常量. 在interface里面的变量都是public st ...
- HDU--2040
亲和数 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submis ...
- eclipse+axis2+webservice开发实例
myeclipse10安装axis2插件 第一步:下载axis2-1.6的插件压缩包,axis2-eclipse-codegen-plugin-1.6.2.zip 和 axis2-eclipse-se ...
- 由阿里巴巴一道笔试题看Java静态代码块、静态函数、动态代码块、构造函数等的执行顺序
一.阿里巴巴笔试题: public class Test { public static int k = 0; public static Test t1 = new Test("t1&qu ...
- linux 下 apt命令集详解
apt命令用法 packagename指代为软件包的名称 apt-get update 在修改/etc/apt/sources.list或/etc/apt/preferences之後运行该命令.此外您 ...
- MFC和Qt优缺点
在网上看到的,拿来和大家一起讨论下. 我曾经使用过来开发过软件,我想和大家分享我使用他们时所体会的不同之处. 我并非一个职业作家,这篇文章可能看起来不如专业的杂志和网站上的那么条理清晰.但是,我在这里 ...
- mac svn .a文件的上传方法
1.首先确认是否安装了Command Line Tools,如果没有,就Xcode-Preference-Downloads,选择Command Line Tools-install就可以了 2.打开 ...
- JFreeChart当鼠标停留在热点提示自定义信息功能
当鼠标停留在数据点时,希望有提示信息显示,但是根据业务需要,我们需要自定义显示一下信息!具体功能实现如下: 首先我们要弄明白,Jfreechart鼠标提示信息显示主要是得到一个数据的map对象,该ma ...
- HDU 5105 Math Problem
让求 f(x)=|a∗x3+b∗x2+c∗x+d|(L≤x≤R)的最大值 这个题目讨论a和b的值,如果a==0的话,那么这个方程就变成了一个一元二次方程,直接找端点和对称轴(如果对称轴在给定的区间内 ...