【素数】 poj 2739 一个数能有多少种连续素数相加方案
简单题 素数打表 根据数据量 用n2算法遍历 开一个save【k】素数存前k个素数和即可。
#include <iostream>
#include <cstdio>
#include <memory.h>
#include <cmath>
using namespace std;
;
];
+];
+];
void make_pri()
{
pri[]=;
pri[]=;
;i<=maxn;i++)
{
pri[i]=;
}
;i*i<=maxn;i++)
{
if(pri[i])
{
for(int j=i*i;j<=maxn;j+=i)
pri[j]=;
}
}
}
void init()
{
memset(save,,sizeof(save));
memset(s,,sizeof(s));
;
s[]=;
;i<=maxn;i++)
{
)
{
s[j++]=i;
}
}
;i<=;i++)
{
save[i]=save[i-]+s[i];
}
}
int main()
{
//freopen("in.txt","r",stdin);
memset(save,,sizeof(save));
make_pri();
init();
int n;
)
{
;
int last;
)
{
;i>=;i--)
{
if(s[i]==n)
{
last=i;
}
}
}
else
{
;i>=;i--)
{
]>n)
{
last=i;
}
}
}
;i--)
{
;j>=;j--)
{
if(save[i]-save[j]==n)
{
cnt++;
}
}
}
cout << cnt << endl;
}
;
}
【素数】 poj 2739 一个数能有多少种连续素数相加方案的更多相关文章
- 剑指offer41:所有和为S的连续正数序列,例如,有多少种连续的正数序列的和为100
1 题目描述 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100.但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数).没多久 ...
- POJ 2739 Sum of Consecutive Prime Numbers( *【素数存表】+暴力枚举 )
Sum of Consecutive Prime Numbers Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 19895 ...
- 筛素数 poj 2739
题目链接:https://vjudge.net/problem/POJ-2739 输入一个数字n,判断有没有一段连续的素数之和大于n,如果有,计算总共有几种. 思路:用素数筛法求出10000以内的素数 ...
- POJ 2739 Sum of Consecutive Prime Numbers【素数打表】
解题思路:给定一个数,判定它由几个连续的素数构成,输出这样的种数 用的筛法素数打表 Sum of Consecutive Prime Numbers Time Limit: 1000MS Memo ...
- 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100。但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数)。没多久,他就得到另一组连续正数和为100的序列:18,19,20,21,22。现在把问题交给你,你能不能也很快的找出所有和为S的连续正数序列? Good Luck!
// test20.cpp : 定义控制台应用程序的入口点. // #include "stdafx.h" #include<iostream> #include< ...
- 【Python】【demo实验3】【显示素数,显示两个数范围内的所有素数】
打印两个整数之间的所有素数: (使用平方根来判断 是否应停止验证该数值是否为素数) for i in range(956253526252,9956253526252): k = 1 if i == ...
- POJ 2739 Sum of Consecutive Prime Numbers(素数)
POJ 2739 Sum of Consecutive Prime Numbers(素数) http://poj.org/problem? id=2739 题意: 给你一个10000以内的自然数X.然 ...
- Sum of Consecutive Prime Numbers POJ - 2739 线性欧拉筛(线性欧拉筛证明)
题意:给一个数 可以写出多少种 连续素数的合 思路:直接线性筛 筛素数 暴力找就行 (素数到n/2就可以停下了,优化一个常数) 其中:线性筛的证明参考:https://blog.csdn.net ...
- N个数依次入栈,出栈顺序有多少种
题目:N个数依次入栈,出栈顺序有多少种? 首先介绍一下卡特兰数:卡特兰数前几项为 : 1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862, 16796, 58786, 2 ...
随机推荐
- Web程序和应用程序服务器[转]
转自:http://hi.baidu.com/lclkathy/blog/item/dae3be36763a47370b55a970.html 一 常见的WEB服务器和应用服务器 在UNIX和LINU ...
- c# 方法重载
在c#中同样的方法名称不一样的参数数量和类型可以实现方法重载 class ResultDisplayer{void DisplayResult(string result){// implementa ...
- 同一级目录js的引入
- 浙大 pat 1047题解
1047. Student List for Course (25) 时间限制 400 ms 内存限制 64000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Y ...
- linux下合并pdf
使用Gost Script和 PDFtk运行如下命令: #gs -q -dNOPAUSE -sDEVICE=pdfwrite -sOUTPUTFILE=Linuxidc.pdf -dBATCH *.p ...
- LeetCode OJ 169. Majority Element
Given an array of size n, find the majority element. The majority element is the element that appear ...
- 感知哈希算法 python 3.4
#!/usr/bin/python # -*- coding: UTF-8 -*- #Less than 10 add to list and sort import glob import os i ...
- NTFS 读写高手进阶 - Windows 格式硬盘 Mac存文件 开启 ...(转载)
常识: 硬盘格式: FAT32 - WIndows 硬盘分区格式, 有点通用性高, 缺点不支持单个大于 4G 的文件. exFAT - Windows 硬盘分区格式, 兼容性低. 稳定性不如 FAT3 ...
- Smarty练习增删改
<?php //将题目表显示在页面 include("../init.inc.php"); include("../DBDA.php"); $db = n ...
- img转data
http://blog.csdn.net/lwjok2007/article/details/50756273