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 ...
随机推荐
- base64编码上传图片java后台接收实例
原文地址:http://blog.csdn.net/tonyfreak/article/details/72522855 思路 前台传以data:image/jpeg;base64,开头的base64 ...
- DFS HDU 5305 Friends
题目传送门 /* 题意:每个点都要有偶数条边,且边染色成相同的两部分,问能有多少种染色方法 DFS+剪枝:按照边数来DFS,每种染色数为该点入度的一半,还有如果点不是偶数边就不DFS 这是别人的DFS ...
- Android 性能优化(10)网络优化( 6)Optimizing General Network Use
Optimizing General Network Use This lesson teaches you to Compress Data Cache Files Locally Optimize ...
- vue中引入swiper插件
这里我们使用npm的方式安装swiper插件. 1.npm install vue-awesome-swiper --save 2.在main.js文件中引入文件 import Vue from 'v ...
- C# 传值和传引用 ( ref out in )
引用类型的变量不直接包含其数据:它包含的是对其数据的引用.当通过值传递引用类型的参数时,有可能更改引用所指向的数据,如某类成员的值(更改属性的值),但是无法更改引用本身的值:也就是说,不能使用相同的引 ...
- linux 常用shell命令 ls
ls:查看文件名和目录,用法:$ ls [选项] 1. $ ls 直接输入ls命令,则列出当前目录下的所有文件和目录,不显示详细信息,如类型,大小,日期权限等. 2. $ ls -l -l 选项,每行 ...
- CF804B Minimum number of steps
思路: 找规律.参考了http://blog.csdn.net/harlow_cheng/article/details/71190999. 实现: #include <iostream> ...
- PHP无符号右移与旋转右移
# PHP 无符号右移 仅用于int形, PHP 的int为32位 # // 右移旋转 function rightRoate($int,$n){ $min = intval(PHP_INT_MAX ...
- python自动化--语言基础线程、生产者消费者示例
进程与线程的区别:进程不共享空间,线程共享地址空间 线程共享空间优缺点:优点:多线程给用户的体验好些,打开时占用的内存比进程少缺点:共享地址空间会相互干扰,甚至有影响 import threading ...
- golang 自定义time.Time json输出格式
工作中使用golang时,遇到了一个问题.声明的struct含time.Time类型.使用json格式化struct时,time.Time被格式化成”2006-01-02T15:04:05.99999 ...