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 ...
随机推荐
- Change ugly fonts in Firefox (KDE)
When you use KDE the fonts in Firefox are ugly. This is the fix: Open with Kate: /home/yourusername/ ...
- div+css模式编写html静态网页例子_仿照网页制作
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- [已解决问题] An error occurred while automatically activating bundle com.android.ide.eclipse.adt
可以参见stackoverflow的解决方案:http://stackoverflow.com/questions/16974349/an-error-occurred-while-automatic ...
- lightoj 1004 dp:数字三角形
题目链接:http://lightoj.com/volume_showproblem.php?problem=1004 #include <cstdio> #include <cst ...
- windows下python安装paramiko
Python中使用SSH需要用到OpenSSH,而OpenSSH依赖于paramiko模块,而paramiko模块又依赖于pycrypto模块,因此要在Python中使用SSH,则需要先安装模块顺序是 ...
- inux常用命令大全
系统信息 arch 显示机器的处理器架构(1) uname -m 显示机器的处理器架构(2) uname -r 显示正在使用的内核版本 dmidecode -q 显示硬件系统部件 - (SMBIOS ...
- memkeys 安装时遇到的问题及解决办法
某天由于某需要,安装tumblr的开源工具memkeys .但还是一如既往地不是一帆风顺. 在./configure 时出现如下错误信息: configure.in:14: error: possib ...
- C#修饰符
声明类的顺序: 访问修饰符+类修饰符 +class+类名 { 成员修饰符+ 成员类型 +成员名称; } C#中类及类型成员权限访问修饰符有以下四类:public,private,protected,i ...
- uva:10340 - All in All(字符串匹配)
题目:10340 - All in All 题目大意:给出字符串s和t,问s是否是t的子串.s若去掉某些字符能和t一样,那么t是s的子串. 解题思路:匹配字符.t的每一个字符和s中的字符匹配.注意这里 ...
- [PWA] 17. Cache the photo
To cache photo, You need to spreate cache db to save the photo. So in wittr example, we cache the te ...