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 ...
随机推荐
- 10.Power of Two-Leetcode
Given an integer, write a function to determine if it is a power of two. class Solution { public: bo ...
- C#页面缓存设置
protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { Sessioninfo(); } Session.R ...
- 多线程高级篇1 — JUC — 只弄到处理高并发集合问题
1.线程池 1.1).什么是线程池? 池( pool ),就是一个容器,所以线程池就是把多个线程对象放到一个容器中 1.2).如何创建线程池? 先来了解几个常识 Executor -- 这是一个接口( ...
- MySQL全面瓦解29:使用Partition功能实现水平分区
1 回顾 上一节我们详细讲解了如何对数据库进行分区操作,包括了 垂直拆分(Scale Up 纵向扩展)和 水平拆分(Scale Out 横向扩展) ,同时简要整理了水平分区的几种策略,现在来回顾一下. ...
- hive向mysql导入数据sqoop命令出错
报错信息: java.lang.Exception: java.io.IOException: java.lang.ClassNotFoundException: info at org.apache ...
- absent, absolute, absorb
absent Absenteeism is a habitual [习惯性的] pattern of absence from a duty or obligation [职责] without go ...
- CSS系列,三栏布局的四种方法
三栏布局.两栏布局都是我们在平时项目里经常使用的,今天我们来玩一下三栏布局的四种写法,以及它的使用场景. 所谓三栏布局就是指页面分为左中右三部分然后对中间一部分做自适应的一种布局方式. 1.绝对定位法 ...
- 转Android Canvas和Paint基本使用
Android Canvas和Paint基本使用 这篇文章主要介绍下画笔Paint和画布Canvas的基本使用 1.Paint 创建对象Paint mPaint = new Paint(); 常 ...
- 【Java多线程】线程池-ThreadPoolExecutor
ThreadPoolExecutor提供了四个构造方法: 我们以最后一个构造方法(参数最多的那个),对其参数进行解释: public ThreadPoolExecutor(int corePoolSi ...
- Gitlab-CICD实践篇
一.背景 随着公司项目使用gitlab越来越多,业务发布的次数越来越频繁,对于发布效率提出了更高的要求.从2012开始,Gitlab官方开始集成了Continuous Integration (CI) ...