首页 技术 正文
技术 2022年11月14日
0 收藏 907 点赞 5,088 浏览 1503 个字

HDU 2012 素数判定

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 72727    Accepted Submission(s): 25323

Problem Description对于表达式n^2+n+41,当n在(x,y)范围内取整数值时(包括x,y)(-39<=x<y<=50),判定该表达式的值是否都为素数。 Input输入数据有多组,每组占一行,由两个整数x,y组成,当x=0,y=0时,表示输入结束,该行不做处理。 Output对于每个给定范围内的取值,如果表达式的值都为素数,则输出"OK",否则请输出“Sorry”,每组输出占一行。
 Sample Input

0 1
0 0

 Sample Output

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;}

FZU Problem 1756 FactorSum

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

1234

 Sample Output

0113

思路:对于每个数字,他的倍数都要加上他;比如 我们一共要求到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;}

版权声明:本文为博主原创文章,未经博主允许不得转载。

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,909
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,434
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,249
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,060
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,692
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,730