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 代表 ...
随机推荐
- CSU1312:榜单(模拟)
Description ZZY很喜欢流行音乐,每周都要跟踪世界各地各种榜单,例如Oricon和Billboard,现在给出每周各个单曲的销量请给出每周的TOP5以及TOP5中各个单曲的浮动情况. 量的 ...
- etrace 跟踪程序函数动态执行流程
https://github.com/elcritch/etrace 窗口1: 监控窗口,执行监控程序,显示监控结果 [root@monitor example]# pwd /root/etrace- ...
- css选择器优化
css选择器优化@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@impor ...
- C#解leetcode 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- selenium+eclipse+python环境
1.下载并安装jdk,配置环境变量: 2.下载并安装python,配置path系统环境变量:D:\Program Files\python34: 3.安装selenium,在安装好的python路径D ...
- get 和 post的使用.
Two commonly used methods for a request-response between a client and server are: GET and POST. GET ...
- 详解SQL Server 2005 Express下的事件探查器
安装Visual Studio 2008会有附带的SQL Server 2005 Express版 我们开发一般都用那个都不单独安装SQL Server的 大家都知道express版的sql是没有 事 ...
- ASP.NET 导入EXCEL文档
鉴于教务一般都是手动输入学生信息,在未了解本校数据库的客观情况之下,我们准备设计一个导入excel文档中学生信息如数据库的功能.结合网上各类大牛的综合版本出炉.. 首先具体的实现思想如下: 1.先使用 ...
- 【转】iOS-Core-Animation-Advanced-Techniques(五)
原文:http://www.cocoachina.com/ios/20150105/10829.html 图层时间和缓冲 图层时间 时间和空间最大的区别在于,时间不能被复用 -- 弗斯特梅里克 在上面 ...
- [转]Mysql导入导出工具Mysqldump和Source命令用法详解
Mysql本身提供了命令行导出工具Mysqldump和Mysql Source导入命令进行SQL数据导入导出工作,通过Mysql命令行导出工具Mysqldump命令能够将Mysql数据导出为文本格式( ...