Codeforces Round #240 (Div. 2) C Mashmokh and Numbers
Mashmokh and Numbers
It's holiday. Mashmokh and his boss, Bimokh, are playing a game invented by Mashmokh.
In this game Mashmokh writes sequence of n distinct integers on the board. Then Bimokh makes several (possibly zero) moves. On the first move he removes the first and the second integer from from the board, on the second move he removes the first and the second integer of the remaining sequence from the board, and so on. Bimokh stops when the board contains less than two numbers. When Bimokh removes numbers x and yfrom the board, he gets gcd(x, y) points. At the beginning of the game Bimokh has zero points.
Mashmokh wants to win in the game. For this reason he wants his boss to get exactly k points in total. But the guy doesn't know how choose the initial sequence in the right way.
Please, help him. Find n distinct integers a1, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge numbers. Therefore each of these integers must be at most 109.
The first line of input contains two space-separated integers n, k (1 ≤ n ≤ 105; 0 ≤ k ≤ 108).
If such sequence doesn't exist output -1 otherwise output n distinct space-separated integers a1, a2, ..., an (1 ≤ ai ≤ 109).
5 2
1 2 3 4 5
5 3
2 4 3 7 1
7 2
-1
题意:找出一组数列,满足每相邻的两个数的最大公因数和为给定的值。
sl:无以言状的水题,最终挂了,为什么呢,我把最后一个数字写的太小了。在知道直接0走起。
相邻两个数字互素。利用这点很容易求出答案。
1 #include<cstdio>
2 #include<cstring>
3 #include<algorithm>
4 #include<queue>
5 using namespace std;
6 typedef long long LL;
7 const int MAX = ;
8 int main()
9 {
int n,k;
while(scanf("%d %d",&n,&k)==)
{
if(n==&&k!=) printf("-1\n");
else if(n==&&k==) printf("1\n");
else if(n/>k) printf("-1\n");
else
{
int a=,b=;
int t=n/; t*=; int x=n/;
int last=k-(x-);
for(int i=;i<x;i++)
{
if(a!=last&&b!=last&&a!=*last&&b!=*last)
{
if(i==) printf("%d %d",a,b),a+=, b+=;
else printf(" %d %d",a,b),a+=, b+=;
}
else
{
while(a==last||b==last||a==*last||b==*last)
a+=, b+=;
if(i==) printf("%d %d",a,b),a+=, b+=;
else printf(" %d %d",a,b),a+=, b+=;
}
}
if(x!=&&last!=) printf(" %d %d",*last,last);
else if(last!=&&x==) printf("%d %d",*last,last);
else if(x!=&&last==) printf(" 99999997 99999998");
else if(last==&&x==) printf("99999997 99999998");
if(n%) printf(" 1000000000");
printf("\n");
}
}
return ;
}
Codeforces Round #240 (Div. 2) C Mashmokh and Numbers的更多相关文章
- Codeforces Round #240 (Div. 2)->A. Mashmokh and Lights
A. Mashmokh and Lights time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #240 (Div. 1) B. Mashmokh and ACM DP
B. Mashmokh and ACM ...
- Codeforces Round #240 (Div. 2)(A -- D)
点我看题目 A. Mashmokh and Lights time limit per test:1 secondmemory limit per test:256 megabytesinput:st ...
- Codeforces Round #240 (Div. 1)B---Mashmokh and ACM(水dp)
Mashmokh's boss, Bimokh, didn't like Mashmokh. So he fired him. Mashmokh decided to go to university ...
- Codeforces Round #240 (Div. 2) B 好题
B. Mashmokh and Tokens time limit per test 1 second memory limit per test 256 megabytes input standa ...
- Codeforces Round #240 (Div. 2) D
, b2, ..., bl (1 ≤ b1 ≤ b2 ≤ ... ≤ bl ≤ n) is called good if each number divides (without a remainde ...
- Codeforces Round #240 (Div. 2) 题解
A: 1分钟题,往后扫一遍 int a[MAXN]; int vis[MAXN]; int main(){ int n,m; cin>>n>>m; MEM(vis,); ; i ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers(如压力dp)
Roman and Numbers time limit per test 4 seconds memory limit per test 512 megabytes input standard i ...
- Codeforces Round #235 (Div. 2) D. Roman and Numbers 状压dp+数位dp
题目链接: http://codeforces.com/problemset/problem/401/D D. Roman and Numbers time limit per test4 secon ...
随机推荐
- Django day 37 网站视频的播放,购物车接口,优惠券表分析
一:网站视频的播放, 二:购物车接口, 三:优惠券表分析
- [Usaco2018 Open]Milking Order
Description Farmer John的N头奶牛(1≤N≤10^5),仍然编号为1-N,正好闲得发慌.因此,她们发展了一个与Farmer John每天早上为她们挤牛奶的时候的排队顺序相关的复杂 ...
- Light 1289 - LCM from 1 to n (位图标记+素数筛选)
题目链接: http://www.lightoj.com/volume_showproblem.php?problem=1289 题目描述: 给出一个n,求出lcm(1,2,3......n)为多少? ...
- 因Window服务器自动更新并重启导致WebSphere服务停止服务故障一例
最近公司购买了两台Windows Server 2008 R2服务器用于提供提供Web服务,A机器安装了IHS+DM+WAS8.5集群,B机器安装了Oracle11gR2用于数据存储,两台机器均可连接 ...
- EditText(1)EditText的类型和回车键的行为
1,常见类型 <EditText android:id="@+id/email_address" android:layout_width="fill_parent ...
- [转]我要学ASP.NET MVC 3.0(十二): MVC 3.0 使用自定义的Html控件
本文转自:http://www.cnblogs.com/lukun/archive/2011/08/05/2128693.html 概述 在ASP.NET MVC框架中已经封装了很多基于Html标 ...
- SQL server中的T-SQL语句
首先点击新建查询 如下图所示 创建数据库:create database 数据库名称 使用数据库:use 数据库名称 创建表:create table 表名 ( 代码 ) 输入完成执行时需选中 如果需 ...
- NodeJs学习记录(一)初步学习,杂乱备忘
2016/12/26 星期一 1.在win7下安装了NodeJs 1)进入官网 https://nodejs.org/en/download/,下载对应的安装包,我目前下载的是node-v6.2.0- ...
- 图标文件ico制作以及使用说明
今天说一个图标文件——ico.我们在pc端浏览网页的时候网页栏那块都会显示一个本网站特有的图片,就是我们说的ico了.示例:<link href="image/favicon.ico& ...
- 业余开发Android App的架构演变
闲暇之余,开发了一款休闲类app,虽然用户量不多,但确实花了不少心血在这上面.然而,开发出来的结果,与之前想好的架构,还是有不少区别. 下面,记录下这款app架构的演变: 最初,只想写个app,能与机 ...