Sum of Consecutive Prime Numbers(poj2739)
| Time Limit: 1000MS | Memory Limit: 65536K | |
| Total Submissions: 22019 | Accepted: 12051 |
Description
numbers, so neither 7 + 13 nor 3 + 5 + 5 + 7 is a valid representation for the integer 20.
Your mission is to write a program that reports the number of representations for the given positive integer.
Input
Output
Sample Input
2 3 17 41 20 666 12 53 0
Sample Output
1 1 2 3 0 0 1 2
思路:先筛选0到10000的素数,尺取跑一遍。
1 import java.util.*; 2 import java.lang.*; 3 import java.io.*; 4 5 public class Main { 6 public static void main(final String[] args) { 7 Scanner in = new Scanner(System.in); 8 int n, i, j, k, p, q; 9 int aa[] = new int[20000];10 int bb[] = new int[20000];11 Arrays.fill(aa, 0);12 aa[1] = 1;13 aa[0] = 1;14 int cnt = 0;15 for (i = 2; i <= 100; i++) {16 if (aa[i] == 0) {17 for (j = i; i * j <= 10000; j++) {18 aa[i * j] = 1;19 }20 }21 22 }23 for (i = 0; i <= 10000; i++) {24 if (aa[i] == 0) {25 bb[cnt++] = i;26 }27 }28 int ss = 1;29 while (ss == 1) {30 k = in.nextInt();31 int ans = 0;32 if (k == 0) {33 break;34 } else {35 int sum = 0;36 int ll = 0;37 int rr = 0;38 while (ss == 1) {39 if (rr > cnt) {40 break;41 }42 if (bb[rr] > k) {43 break;44 }45 if (ll > rr) {46 break;47 }48 while (ss == 1) {49 sum += bb[rr];50 if (sum >= k) {51 break;52 } else {53 rr++;54 }55 if(rr>cnt)56 {break;}57 }58 if (sum == k) {59 ans++;60 }61 sum -= bb[ll];62 sum -= bb[rr];63 ll++;64 }65 }66 System.out.println(ans);67 }return ;68 }69 }
Sum of Consecutive Prime Numbers(poj2739)的更多相关文章
- POJ2739 Sum of Consecutive Prime Numbers(尺取法)
POJ2739 Sum of Consecutive Prime Numbers 题目大意:给出一个整数,如果有一段连续的素数之和等于该数,即满足要求,求出这种连续的素数的个数 水题:艾氏筛法打表+尺 ...
- POJ2739 Sum of Consecutive Prime Numbers 2017-05-31 09:33 47人阅读 评论(0) 收藏
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 25225 ...
- POJ 2739. Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 20050 ...
- POJ 2739 Sum of Consecutive Prime Numbers(尺取法)
题目链接: 传送门 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Description S ...
- Sum of Consecutive Prime Numbers
Sum of Consecutive Prime Numbers http://poj.org/problem?id=2739 Time Limit: 1000MS Memory Limit: 6 ...
- poj 2739 Sum of Consecutive Prime Numbers 素数 读题 难度:0
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19697 ...
- POJ.2739 Sum of Consecutive Prime Numbers(水)
POJ.2739 Sum of Consecutive Prime Numbers(水) 代码总览 #include <cstdio> #include <cstring> # ...
- poj 2379 Sum of Consecutive Prime Numbers
...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
随机推荐
- ubuntu 常用指令
1.进入到root权限的指令 sudo su,效果同su,只是不需要root的密码,而需要当前用户的密码.(亲测有效) 2.从root权限里面退出到 普通用户模式 exit---指令亲测有效 3.下载 ...
- .Net调用Java的实现方法
一. IKVM 1.1下载配置IKVM 1.1.1. 下载路径 http://www.ikvm.net/index.html 1.1.2. 设置路径 解压ikvm-0.42.0.3.zip,并将%IK ...
- 以DevExpress开发的WinFrom程序的多语言功能的实现
以DevExpress开发的WinFrom程序的多语言功能的实现 写在前面: 多语言切换功能在Winform程序中是经常遇到的需求,尤其是需要给国外客户使用的情况下,多语言功能是必不可少的.前一段时间 ...
- 日常Java 2021/11/4
ServerSocket类的方法服务器应用程序通过使用java.net.ServerSocket类以获取一个端口,并且侦听客户端请求. 构造方法: public ServerSocket(int po ...
- C/C++ Qt 数据库与ComBox多级联动
Qt中的SQL数据库组件可以与ComBox组件形成多级联动效果,在日常开发中多级联动效果应用非常广泛,例如当我们选择指定用户时,我们让其在另一个ComBox组件中列举出该用户所维护的主机列表,又或者当 ...
- words in English that contradict themselves
[S1E10, TBBT]Leonard: I don't get it. I already told her a lie. Why would I replace it with a differ ...
- 文件和目录之间建立链接 (ln)
- Spark(七)【RDD的持久化Cache和CheckPoint】
RDD的持久化 1. RDD Cache缓存 RDD通过Cache或者Persist方法将前面的计算结果缓存,默认情况下会把数据以缓存在JVM的堆内存中.但是并不是这两个方法被调用时立即缓存,而是 ...
- Output of C++ Program | Set 11
Predict the output of following C++ programs. Question 1 1 #include<iostream> 2 using namespac ...
- 2.8 rust 枚举与模式匹配
Enums and Pattern Matching 摘要 枚举定义 enum IpAddrKind { V4, V6, } 枚举方法 fn main() { enum Message { Quit, ...