codeforces C. Mashmokh and Numbers
题意:给你n和k,然后让你找出n个数使得gcd(a1,a2)+gcd(a3,a4)+......的和等于k;
思路:如果n为奇数,让前n-3个数的相邻两个数都为1,n-2和n-1两个数gcd为k-ans;ans为前n-3个数的和。为偶数的话,让前n-2个数的相邻两个数都为1,n和n-1两个数gcd为k-ans;
#include <cstdio>
#include <cmath>
#include <cstring>
#include <vector>
#include <algorithm>
#define maxn 10000
#define ll long long
using namespace std; int n,k;
vector<int>q; int main()
{
scanf("%d%d",&n,&k);
if((n%==&&(n/)>k)||(n%!=&&(n-)/>k))
{
printf("-1\n");
}
else
{
if(n==&&k==)
{
printf("1\n");
return ;
}
else if(n==&&k>)
{
printf("-1\n");
return ;
}
if(n%==)
{
int ans=;
ll c=;
for(int i=; i<=n-; i+=)
{
printf("%lld %lld ",c,c-);
c-=;
ans++;
}
printf("%lld %lld\n",(ll)(k-ans),(ll)((k-ans)*));
}
else
{
int ans1=;
ll c1=;
for(int i=; i<n-; i+=)
{
printf("%lld %lld ",c1,c1-);
c1-=;
ans1++;
}
printf("%lld %lld",(ll)(k-ans1),(ll)(k-ans1)*);
printf(" %lld\n",c1);
}
}
return ;
}
codeforces C. Mashmokh and Numbers的更多相关文章
- codeforces 414A A. Mashmokh and Numbers(素数筛)
题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #240 (Div. 2) C Mashmokh and Numbers
, a2, ..., an such that his boss will score exactly k points. Also Mashmokh can't memorize too huge ...
- [codeforces 55]D. Beautiful numbers
[codeforces 55]D. Beautiful numbers 试题描述 Volodya is an odd boy and his taste is strange as well. It ...
- codeforces 414D Mashmokh and Water Tanks
codeforces 414D Mashmokh and Water Tanks 题意 题解 \(a_i\):第 \(i\) 层的结点个数. \(b_i\):第 \(i\) 层初始有水的结点个数. 如 ...
- Mashmokh and Numbers CodeForces - 415C
题意:就是n个数和k,每次按顺序那两个数,最大公约数的和为k. 思路:注意:当n=1,k>0时一定不存在,还有n=1,k=0时为1即可. 然后再正常情况下,第一组的最大公约数为k-n/2+1即可 ...
- CodeForces - 1245A Good ol' Numbers Coloring (思维)
Codeforces Round #597 (Div. 2 Consider the set of all nonnegative integers: 0,1,2,-. Given two integ ...
- CodeForces 682A Alyona and Numbers (水题)
Alyona and Numbers 题目链接: http://acm.hust.edu.cn/vjudge/contest/121333#problem/A Description After fi ...
- Codeforces 449D Jzzhu and Numbers
http://codeforces.com/problemset/problem/449/D 题意:给n个数,求and起来最后为0的集合方案数有多少 思路:考虑容斥,ans=(-1)^k*num(k) ...
- Codeforces 414B Mashmokh and ACM
http://codeforces.com/problemset/problem/414/B 题目大意: 题意:一个序列B1,B2...Bl如果是好的,必须满足Bi | Bi + 1(a | b 代表 ...
随机推荐
- 23web app实现上下左右滑动
转载请说明出处:http://blog.csdn.net/wowkk/article/category/1619287 (创意系列) /*最近项目须要苹果电脑,假设您支持学生创业并愿意赞助我们一台,请 ...
- JS浮点类型计算
/* ---------------- JS浮点数运算重置 ---------------- */ //加法函数 //调用:accAdd(arg1,arg2) //返回值:arg1加上arg2的精确结 ...
- mysql 锁 实验
CREATE TABLE `kk` ( `a` ) NOT NULL, `b` ) NOT NULL, `c` ) NOT NULL, PRIMARY KEY (`a`), UNIQUE KEY `b ...
- Svg图片在asp网站上的使用
最近需要做一个动态的根据后台的返回数据而动态显示的导航图,然后我就采用了jquery+ajax+SVG矢量图来实现这个功能. 首先,客户给了个ai的矢量图,我对这一块不懂就找以前同事帮我转成了svg图 ...
- HTML - 键盘事件
Keyboard 事件 onkeydown: 在用户按下按键时触发. onkeypress: 在用户敲击按钮时触发. onkeyup: 当用户释放按键时触发. 示例 <!DOCTYPE html ...
- C# 里窗体里(windows form)怎么播放音乐
在.NET的winform里面,没有托管的音乐播放器,API只能播放WAV格式,对于MP3等形式的音频文件,就要依赖于 MediaPlayer里,嘿嘿 使用的方法: 在toolbox上点右键,选择“选 ...
- java判断字符串是否为空的方法总结
http://blog.csdn.net/qq799499343/article/details/8492672 以下是java 判断字符串是否为空的四种方法: 方法一: 最多人使用的一个方法, 直观 ...
- C#-日期格式表
自定义格式表: 格式模式 说明 d 月中的某一天.一位数的日期没有前导零. dd 月中的某一天.一位数的日期有一个前导零. ...
- Tomcat-java.lang.IllegalArgumentException: Document base F:apps does not exist or is not a readable
启动Tomcat的时候,报错:java.lang.IllegalArgumentException: Document base F:apps does not exist or is not a r ...
- mksquash_lzma-3.2 编译调试记录
今天在编译mksquash_lzma-3.2的时候出现了如下问题: /home/test/RT288x_SDK/toolchain/mksquash_lzma-3.2/lzma443/C/7zip/C ...