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 ...
随机推荐
- SRM 402(1-250pt, 1-500pt)
DIV1 250pt 题意:对于任意一个由1-n组成的数列,其原始顺序为1,2,3..n.给出1~n的一个排列a[n],要通过swp操作将其变回原始顺序.当i < j且a[i] > a[j ...
- windows server作为文件服务器如何精细控制权限
最近使用windows server 2003搭建了文件服务器,对于其中关于共享文件权限的精细控制有了较深的体会. 当前实现基本的共享文件目录结构是(上传图片真心费劲,大家将就一下吧): |--部门1 ...
- GitHub 的分支创建与合并
一个Git仓库可以维护很多开发分支.现在我们来创建一个新的叫"experimental"的分支: $ git branch experimental 如果你运行下面这条命令: $ ...
- selenium webdriver启动IE浏览器失败的解决办法
通过selenium webdriver启动IE浏览器失败,报错:selenium.common.exceptions.WebDriverException: Message: Unexpected ...
- java+ mysql 给所有的表添加假数据
需求:别的项目, 代码扣过来了, 数据库也拿过来了, 但是数据库全是空表, 一共700 张表,需求是给表添加假数据,让它能运行起来. 一下是代码实现: 1.数据库连接: public static C ...
- Java EE 7 / JAX-RS 2.0: Simple REST API Authentication & Authorization with Custom HTTP Header--reference
REST has made a lot of conveniences when it comes to implementing web services with the already avai ...
- UITextField控件处理键盘弹出时遮住输入框的问题
原文连接: http://www.devdiv.com/thread-70159-1-1.html 实现以下三个方法,如果弹出的键盘会遮住输入框 ,整体的界面会向上移动,这样就不会遮住输入框了.自己增 ...
- Java基础知识强化之IO流笔记09:File类功能
详见如下: Android(java)学习笔记87:File类使用
- NYOJ 47过河问题
主要思路:先排序.有两种可能是最小的情况,一种是让最小的去带着最大的过去,然后最小的再回来,还有一种就是先最小的和第二小的一块过去, 然后最小的回来,让最大的和第二大的过去,接着第二小的回来,第二小和 ...
- 没有懂的leetcode
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in ...