HDU 2012 FZU 1756关于素数的一些水题
HDU 2012 素数判定
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 72727 Accepted Submission(s): 25323
0 1
0 0
OK
思路:筛选法求素数
#include<iostream>
using namespace std;
bool bf[2600];
void getss(){
for(int i=2;i<2600;i++)
{
if(!bf[i]){
for(int j=2;j*i<2600;j++){
bf[i*j]=true;
}
} }
}
int main(){
memset(bf,false,sizeof(bf));
getss();
int x,y;
bool is;
while(cin>>x>>y){
if(x==0&&y==0)break;
is=true;
for(int k=x;k<=y;k++){
if(bf[k*k+k+41]==true){
is=false;break;
}
}
if(is==true) cout<<"OK"<<endl;
else cout<<"Sorry"<<endl;
}
return 0; }
Accept: 429 Submit: 1134
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Give you a signed integer n (n<=10000), please tell me the sum of its all non-negative factors, and all its factors must larger than zero. Say, give you 12, you know, 1,2,3,4,6 are its factors. So the answer would be 1+2+3+4+6=16. if n < 0 , just output
"0"
There are several test cases, for evey case, there is exactly one line containing an integer N (N<=10000).
Sample Input
Sample Output
思路:对于每个数字,他的倍数都要加上他;比如 我们一共要求到6;那么从一开始是一的倍数(不超过6)的都要加1;直到6;然后在从2开始 以此类推;
#include<iostream>
using namespace std;
int bf[10001];
int main(){
memset(bf,0,sizeof(bf));
for(int i=1;i<=10000;i++)
for(int j=2;i*j<=10000;j++){
bf[i*j]+=i;
}
int n;
while(cin>>n){
if(n<0)cout<<0<<endl; else cout<<bf[n]<<endl;
}
return 0; }
版权声明:本文为博主原创文章,未经博主允许不得转载。
HDU 2012 FZU 1756关于素数的一些水题的更多相关文章
- HDU 5832 A water problem (带坑水题)
A water problem 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5832 Description Two planets named H ...
- HDU 5889 Barricade(最短路+最小割水题)
Barricade Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total ...
- hdu 5104 素数打表水题
http://acm.hdu.edu.cn/showproblem.php?pid=5104 找元组数量,满足p1<=p2<=p3且p1+p2+p3=n且都是素数 不用素数打表都能过,数据 ...
- POJ1595_Prime Cuts【素数】【水题】
Prime Cuts Time Limit: 1000MSMemory Limit: 10000K Total Submissions: 10464Accepted: 3994 Description ...
- POJ 1595 素数打表水题
[题意简述]:给出N和C,让我们求出N以内的包含N的素数,然后依据若N以内的素数为奇数个,就将中间2*c-1个素数输出:若为偶数个.就将中间2*c个素数输出. [分析]:仅仅要题意理解就简单了. 详见 ...
- hdu 5742 It's All In The Mind 水题
It's All In The Mind 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5742 Description Professor Zhan ...
- hdu 1038 Biker's Trip Odometer(水题)
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1038 Biker's Trip Odometer Time Limit: 2000/1000 MS ...
- HDU 2066 一个人的旅行(dijkstra水题+判重边)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2066 题目大意:输入数据有多组,每组的第一行是三个整数T,S和D,表示有T条路,和草儿家相邻的城市的有 ...
- hdu 5538 House Building(长春现场赛——水题)
题目链接:acm.hdu.edu.cn/showproblem.php?pid=5538 House Building Time Limit: 2000/1000 MS (Java/Others) ...
随机推荐
- 追溯了解Ubuntu之------基本命令操作(叁)
在使用Ubuntu中的一些基本命令与Linux中是有区别的: 1. 查看Ubuntu系统位数:uname -ar 或 getconf LONG_BIT 2. 获取Ubu ...
- 开发Web版一对一远程直播教室只需30分钟 - 使用face2face网络教室
转载自:https://blog.csdn.net/wo_shi_ma_nong/article/details/88110111 在“为网站开发远程直播教室的折腾过程及最终实现”中,介绍了如何使用f ...
- redis-数据类型及命令
redis五大数据类型:string(字符串),hash(哈希,类似java的Map),list(列表),set(集合),zset(有序集合) 1.redis的键(key) keys 查询数据库中的k ...
- ARMCC中$Super$$和$Sub$$的使用
代码: extern int $Super$$main(void); /* re-define main function */ int $Sub$$main(void) { rt_hw_interr ...
- 检测com端口代码实现
1:scan HRESULT CDevHound::Scan(const vector<CString> &guiInfo, vector<DEV_INFO> & ...
- css3动画性能优化--针对移动端卡顿问题
一.使用css,jquery,canvas制作动画 1.Canvas 优点:性能好,强大,支持多数浏览器(除了IE6.IE7.IE8),画出来的图形可以直接保存为 .png 或者 .jpg的图形: 缺 ...
- 手动安装R包
1,先将R包下载到本地 2,getwd() setwd("F:\\CNV\\Paper\\Case-control\\mHMM") 3, install.packages(&quo ...
- pyhton习题20190201
#20190131'''检查ipV4的有效性,有效则返回True,否则返回False,(提示使用split函数进行分割)'''import osdef print_ping_ip(ip): s = o ...
- 20155330 实验三 敏捷开发与XP实践
20155330 实验三 敏捷开发与XP实践 实验内容 XP基础 XP核心实践 相关工具 实验步骤 (一)敏捷开发与XP 软件工程是把系统的.有序的.可量化的方法应用到软件的开发.运营和维护上的过程. ...
- MySql Host is blocked because of many connection errors; unblock with 'mysqladmin flush-hosts' 的解决方法
解决方法如下: 方法 1.在线修改提高允许的max_connection_errors数量: A. 登录Mysql数据库查看max_connection_errors: mysql>show ...