杭电POJ-2161-Primes
来源:互联网 发布:java将图片生成二维码 编辑:程序博客网 时间:2024/06/03 21:34
题目描述:
Problem DescriptionWrite a program to read in a list of integers and determine whether or not each number is prime. A number, n, is prime if its only divisors are 1 and n. For this problem, the numbers 1 and 2 are not considered primes. InputEach input line contains a single integer. The list of integers is terminated with a number<= 0. You may assume that the input contains at most 250 numbers and each number is less than or equal to 16000. OutputThe output should consists of one line for every number, where each line first lists the problem number, followed by a colon and space, followed by "yes" or "no". Sample Input12345170 Sample Output1: no2: no3: yes4: no5: yes6: yes个人理解:
需要素数打表 另外注意是<=0才结束 其次就是 2在这道题目中不是素数
运行结果:
ResultMemoryTimeLanguageCode lengthAccepted1840k0MSC373BAC代码:# include <stdio.h># include <math.h>char A[16001]={"\0"};int main(){ int m=0,n=1,i,j,Q=sqrt(M); for(i=2;i<=Q;i++)//改进的埃氏筛法O(sqrt(N)*log(long(N))) if(!A[i])for(j=i+i;j<M;j+=i) A[j]=1; A[1]=A[2]=1;//将2变为质数 scanf("%d",&n); while(n>0) { printf("%d: %s\n",++m,A[n]?"no":"yes"); scanf("%d",&n); } return 0;}
阅读全文
0 0
- 杭电POJ-2161-Primes
- 杭电POJ-primes
- 杭电5104Primes Problem
- POJ-Primes
- 2013杭电warm_up1 1010 Difference Between Primes
- poj 3978 Primes
- Primes 2161
- POJ 1165 The Primes 笔记
- HDU 2161 Primes 数论
- hdu 2161 Primes
- hdu-2161-Primes
- hdu 2161 Primes
- Primes hdoj 2161
- hd 2161 Primes
- Primes HDU 2161
- hdu 2161 Primes
- hdu 2161 Primes
- [HDU 2161] Primes
- mysql之 mysql 5.6不停机主主搭建(活跃双主基于日志点复制)
- keras——常用层
- Unity3D基本入门及功能介绍
- WebService之Axis2引擎的使用教程
- JavaScript之异步
- 杭电POJ-2161-Primes
- 堡垒机的实现
- pl/sqldeveloper远程连接数据库方法
- linux应用调试技术之GDB和GDBServer
- 设计模式之适配器模式
- Java多线程之synchronized与Lock
- JavaWeb实现文件上传下载功能实例解析
- Python Numpy 学习笔记
- 离散题目四(求交集)