[暑假集训--数论]poj2034 Anti-prime Sequences
We can extend the definition by defining a degree danti-prime sequence as one where all consecutive subsequences of length 2,3,...,d sum to a composite number. The sequence above is a degree 2 anti-prime sequence, but not a degree 3, since the subsequence 5, 4, 2 sums to 11. The lexicographically .rst degree 3 anti-prime sequence for these numbers is 1,3,5,4,6,2,10,8,7,9.
Input
Output
No anti-prime sequence exists.
Sample Input
1 10 2
1 10 3
1 10 5
40 60 7
0 0 0
Sample Output
1,3,5,4,2,6,9,7,8,10
1,3,5,4,6,2,10,8,7,9
No anti-prime sequence exists.
40,41,43,42,44,46,45,47,48,50,55,53,52,60,56,49,51,59,58,57,54
需要一个 l 到 r 的排列,使得任意一个长度是2,3,...,k的子串当中子串和都不是质数
直接搜就是了
#include<cstdio>
#include<iostream>
#include<cstring>
#define LL long long
using namespace std;
inline LL read()
{
LL x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int l,r,d,haveans=;
bool mk[];
bool mrk[];
int s[];
int p[],len;
inline void getp()
{
for (int i=;i<=;i++)
{
if (!mk[i])
{
p[++len]=i;
for (int j=*i;j<=;j+=i)mk[j]=;
}
}
}
inline void dfs(int now)
{
if (now==r+)
{
for (int i=l;i<r;i++)printf("%d,",s[i]);
printf("%d\n",s[r]);
haveans=;
return;
}
for (int i=l;i<=r;i++)
{
if (mrk[i])continue;
int sum=i,mrk2=;
for (int j=now-;j>=max(l,now-d+);j--)
{
sum+=s[j];
if(!mk[sum]){mrk2=;break;}
}
if (!mrk2)continue;
mrk[i]=;
s[now]=i;
dfs(now+);
if (haveans)return;
s[now]=;
mrk[i]=;
}
}
int main()
{
getp();
while (~scanf("%d%d%d",&l,&r,&d)&&l+r+d)
{
memset(mrk,,sizeof(mrk));
haveans=;
dfs(l);
if (!haveans)puts("No anti-prime sequence exists.");
}
}
poj 2034
[暑假集训--数论]poj2034 Anti-prime Sequences的更多相关文章
- [暑假集训--数论]hdu2136 Largest prime factor
Everybody knows any number can be combined by the prime number. Now, your task is telling me what po ...
- [暑假集训--数论]poj1365 Prime Land
Everybody in the Prime Land is using a prime base number system. In this system, each positive integ ...
- [暑假集训--数论]poj1595 Prime Cuts
A prime number is a counting number (1, 2, 3, ...) that is evenly divisible only by 1 and itself. In ...
- [暑假集训--数论]poj3518 Prime Gap
The sequence of n − 1 consecutive composite numbers (positive integers that are not prime and not eq ...
- [暑假集训--数论]poj2262 Goldbach's Conjecture
In 1742, Christian Goldbach, a German amateur mathematician, sent a letter to Leonhard Euler in whic ...
- [暑假集训--数论]poj2909 Goldbach's Conjecture
For any even number n greater than or equal to 4, there exists at least one pair of prime numbers p1 ...
- [暑假集训--数论]poj2773 Happy 2006
Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD ...
- [暑假集训--数论]hdu1019 Least Common Multiple
The least common multiple (LCM) of a set of positive integers is the smallest positive integer which ...
- [暑假集训--数论]poj2115 C Looooops
A Compiler Mystery: We are given a C-language style for loop of type for (variable = A; variable != ...
随机推荐
- Bootstrap 附加导航(Affix)插件
bootstrap 附加导航(Affix)插件允许某个div元素固定到页面中的某个位置.您可以打开或关闭使用该插件之间进行切换 后续再写
- c++ question 003 求两数大者?
#include <iostream>using namespace std; int main(){ //求两数中的大者? int a,b; cin>>a>>b; ...
- Datatable 省略显示列中内容,当鼠标放在内容上,悬浮显示全部内容
第一种方法是网上看到的,没成功,贴出来参考一下 <!DOCTYPE html> <html lang="en"> <head> <meta ...
- Python操作SQLLite(基本操作)
SQLite 是一个软件库,实现了自给自足的.无服务器的.零配置的.事务性的 SQL 数据库引擎.SQLite 是在世界上最广泛部署的 SQL 数据库引擎.SQLite 源代码不受版权限制. Pyth ...
- django处理上传文件配置
1.sttings中配置 'django.template.context_processors.media' TEMPLATES = [ { 'BACKEND': 'django.template. ...
- 库函数的使用:sscanf的使用方法
先贴代码,可以看懂代码的直接看代码: /***************************************************** ** Name : sscanf.c ** Auth ...
- HDU 3966 Aragorn's Story 树链拋分
一.写在前面 终于开始开坑link-cut-tree这个了,对于网上找到的大佬的前进路线,进行了一番研发,发现实际上可以实现对于树链拋分的制作.经历了若干长时间之后终于打了出来(为什么每次学什么东西都 ...
- Selenium与PhantomJS【转】
爬虫(Spider),反爬虫(Anti-Spider),反反爬虫(Anti-Anti-Spider) 之间恢宏壮阔的斗争... Day 1 小莫想要某站上所有的电影,写了标准的爬虫(基于HttpCli ...
- mysql进阶二
数据库存储数据的特点: 1.数据存放到表中,然后表再放到库中 2.一个库中可以有多张表,每张表具有唯一的表名来标识自己 3.表中有一个或多个列,列又称为“字段” 数据库常见的管理系统 mysql.or ...
- Pre 自动换行和手动换行
pre { white-space: pre-wrap; white-space: -moz-pre-wrap; white-space: -pre-wrap; white-space: -o-pre ...