题面在这里!

锻炼脑子的小构造题。。。

一开始被 a[]<=30000 且 序列 gcd = 1所困扰,但是发现这并没有什么,因为我接下来发现了一种总是能构造出 序列和是6的倍数的方案。

首先如果 n==3 的话输出样例,因为只有这种情况没法用我的方法构造。

否则,考虑两个集合,第一个集合 A 代表<=30000的所有偶数,显然 |A| = 15000;

第二个集合 B 代表 <=30000的所有非偶数的3的倍数,显然 |B| = 5000。

神奇的发现 |A| + |B|  = n可以取的最大值,那么这种方案能否构造成功呢?

设 i 为在B中取的元素个数, j 为在A中取的元素的个数,那么i和j需要满足(假设我们在每个集合都是从小到大取):

1. i+j = n;

2. i<=5000 && i是偶数;

3. j<=15000 && j%3不等于1;

随便证一证都可以发现只要 n>3 那么一定有解(不放心的话你甚至可以打表)

#include<bits/stdc++.h>
#define ll long long
using namespace std; bool v[30005];
int n,a[20005],t; int main(){
scanf("%d",&n);
if(n==3){ puts("2 5 63"); return 0;}
for(int i=2;i<n;i+=2) if((n-i)<=15000&&i<=5000&&(n-i)%3!=1){
for(int j=2,c=1;j<=30000&&c+i<=n;j+=2,c++) printf("%d ",j);
for(int j=3,c=1;j<=30000&&c<=i;j+=3) if(j&1) printf("%d ",j),c++;
break;
}
return 0;
}

AGC 022 B - GCD Sequence的更多相关文章

  1. codeforces #447 894A QAQ 894B Ralph And His Magic Field 894C Marco and GCD Sequence

    A.QAQ 题目大意:从给定的字符串中找出QAQ的个数,三个字母的位置可以不连续 思路:暴力求解,先找到A的位置,往前扫,往后扫寻找Q的个数q1,q2,然 后相乘得到q1*q2,这就是这个A能够找到的 ...

  2. Codeforces 894.C Marco and GCD Sequence

    C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...

  3. Codeforces Round #447 (Div. 2) C. Marco and GCD Sequence【构造/GCD】

    C. Marco and GCD Sequence time limit per test 1 second memory limit per test 256 megabytes input sta ...

  4. codeforces 894C - Marco and GCD Sequence - [有关gcd数学题]

    题目链接:https://cn.vjudge.net/problem/CodeForces-894C In a dream Marco met an elderly man with a pair o ...

  5. 【Codeforces Round #447 (Div. 2) C】Marco and GCD Sequence

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 把gcd(a[1..n])放在输入的n个数之间. [代码] /* 1.Shoud it use long long ? 2.Have ...

  6. CF894C Marco and GCD Sequence

    题目链接:http://codeforces.com/contest/894/problem/C 题目大意: 按照严格递增的顺序给出 \(m\) 个数作为公因数集,请你构造出一个数列,对于数列中的任意 ...

  7. AGC 022 C - Remainder Game

    题面在这里! 显然权值是 2^i 这种的话就是要你贪心,高位能不选就不选. 并且如果 % x 之后再去 % 一个>=x的数是没有用的,所以我们可以把操作的k看成单调递减序列. 这样的话就是一个有 ...

  8. AtCoder Grand Contest 022

    A - Diverse Word Time limit : 2sec / Memory limit : 256MB Score : 300 points Problem Statement Gotou ...

  9. Codeforces Round #447 (Div. 2) 题解 【ABCDE】

    BC都被hack的人生,痛苦. 下面是题解的表演时间: A. QAQ "QAQ" is a word to denote an expression of crying. Imag ...

随机推荐

  1. bzoj 1006 MCS算法

    根据陈丹琪的论文弦图与区间图,求出弦图的完美消除序列之后,反向给每个点染可以染的最小的颜色,这样可以使用最少的颜色染色,染色的方案即为队伍数. 那么我们需要求该图的完美消除序列,使用MCS算法,从后向 ...

  2. Python ctypes 在 Python 2 和 Python 3 中的不同 // 使用ctypes过程中问题汇总

    In Python 2.7, strings are byte-strings by default. In Python 3.x, they are unicode by default. Try ...

  3. Perl6 Bailador框架(2):路径设置

    use v6; use Bailador; =begin pod get表示是get发送 post表示是post发送 get/post 后面的 '/name' 表示是路径 => sub {} 是 ...

  4. python基础===时间处理模块

    时间模块 Python中有很多方便我们处理时间信息的模块 time 模块 datetime 模块 pytz 模块 dateutil 模块 这里我们着重介绍的是前两种 time模块 time.time( ...

  5. python基础===单元测试unittest

    ''' 编写一个名为Employee 的类,其方法__init__()接受名.姓和年薪,并 将它们都存储在属性中.编写一个名为give_raise()的方法,它默认将年薪增加5000 美元,但也能够接 ...

  6. sunos kernel src leakrs

    https://github.com/joede/libezV24 https://github.com/ysei/siriusSparcV8 https://github.com/omniti-la ...

  7. 1000: 恶意IP 课程作业

    1000: 恶意IP Time Limit: 1 Sec  Memory Limit: 16 MB Description Water同学最近好不容易学会了用Tornado建起一个个人的Website ...

  8. Android UI 设计:pixel dip dpi sp density

    1. px (pixels)像素 – 是像素,就是屏幕上实际的像素点单位. dip或dp (device independent pixels)设备独立像素,与设备屏幕有关. sp (scaled p ...

  9. leetcode之Ransom Note

    题目描述: 
Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 a ...

  10. mac系统命令行获取root权限

    刚上手mac本,对系统各种操作不熟,把过程记录下来. 使用内置命令行工具时遇到权限问题,有两种方法,第一种是在每行命令之前加上sudo,例如: 第二种是直接使用roor账户,但是mac系统默认没有ro ...