题意:就是n个数和k,每次按顺序那两个数,最大公约数的和为k。

思路:注意:当n=1,k>0时一定不存在,还有n=1,k=0时为1即可。

   然后再正常情况下,第一组的最大公约数为k-n/2+1即可,后面是含有素数。(本来,配的是素数和素数+1, 然后会怕第一组会重复,后来直解两个素数了,因为第一组要么是特殊的素数要么是合数所以么有必要担心重复)

#include<iostream>
using namespace std;
#define N int(1e7+10)
int prime[N]; //第i个素数是prime[i]
bool vis[N]; //表示i是否是被筛过(素数的倍数会提前被筛去)
bool is_prime[N];//true表示是素数
int Prime(int n)
{
int cnt = ;
for (int i = ; i <= n; ++i)
{
if (!vis[i])
{
prime[cnt++] = i;
is_prime[i] = ;//表示是素数
}
for (int j = ; j < cnt&&i*prime[j] <= n; ++j)
{
vis[i*prime[j]] = ;
if (i%prime[j] == )break; //这里就避免了 例子:6,在2就被筛去,避免了还要经过3又筛一遍。
}
}
return cnt;
}
int num[N];
int main()
{
int cnt = Prime(N);
int n, k;
scanf("%d%d", &n, &k);
int t = n / ;
if (n == && k == )printf("1\n");
else if (k < t || n < )printf("-1\n");
else{
printf("%d %d", (k - t + ) * , (k - t + ) * );
for (int i = ; i <= n; ++i)
printf(" %d", prime[i]);
}
}

Mashmokh and Numbers CodeForces - 415C的更多相关文章

  1. codeforces 414A A. Mashmokh and Numbers(素数筛)

    题目链接: A. Mashmokh and Numbers time limit per test 1 second memory limit per test 256 megabytes input ...

  2. 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 ...

  3. Magic Numbers CodeForces - 628D

    Magic Numbers CodeForces - 628D dp函数中:pos表示当前处理到从前向后的第i位(从1开始编号),remain表示处理到当前位为止共产生了除以m的余数remain. 不 ...

  4. 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-an ...

  5. Really Big Numbers CodeForces - 817C (数学规律+二分)

    C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...

  6. D. Arpa and a list of numbers Codeforces Round #432 (Div. 2, based on IndiaHacks Final Round 2017)

    http://codeforces.com/contest/851/problem/D 分区间操作 #include <cstdio> #include <cstdlib> # ...

  7. AC日记——Little Elephant and Numbers codeforces 221b

    221B - Little Elephant and Numbers 思路: 水题: 代码: #include <cmath> #include <cstdio> #inclu ...

  8. B. Case of Fake Numbers( Codeforces Round #310 (Div. 2) 简单题)

    B. Case of Fake Numbers time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  9. Dividing the numbers CodeForces - 899C (构造)

    大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小. 和/2为偶数最小差一定为0, 和/2为奇数一定为1. 显然可以通过某个前缀和删去一个数得到. #include <iostrea ...

随机推荐

  1. forfiles

    关键命令就这一条了:forfiles.exe /p "D:\Kugou" /m *.tar /d -14 /c "cmd /c del @path" 这条命令的 ...

  2. git+github/码云+VSCode (转载)

    VSCode中使用git,参见. Git安装   在初次使用时如果本地没有安装git会提示先安装git,然后重启vscode. 一.本地操作项目前提: 1)若本地没有git拉取下来的项目,用git克隆 ...

  3. Java框架之Struts2(一)

    在学习Struts2之前,我们要知道Java为什么要有反射机制呢?反射机制可以说是填补Java不能动态访问某一个类的空白.利用反射机制,动态的创建一个对象.动态的访问类的某个属性,而且访问哪一个属性自 ...

  4. 【高并发解决方案】7、HAProxy安装和配置

    简介 HAProxy提供高可用性.负载均衡以及基于TCP和HTTP应用的代理,支持虚拟主机,它是免费.快速并且可靠的一种解决方案. HAProxy特别适用于那些负载特大的web站点,这些站点通常又需要 ...

  5. MySQL ORDER BY主键id加LIMIT限制走错索引

    背景及现象 report_product_sales_data表数据量2800万: 经测试,在当前数据量情况下,order by主键id,limit最大到49的时候可以用到索引report_produ ...

  6. ORM作业

    使用之前学到过的操作实现下面的查询操作:1. 查询平均成绩大于60分的同学的id和平均成绩:2. 查询所有同学的id.姓名.选课的数量.总成绩; 3. 查询姓“李”的老师的个数: 4. 查询没学过“李 ...

  7. virtualenv的使用及pip常用命令

    一.virtualenv 1.用途: virtualenv------用来建立一个虚拟的python环境,一个专属于项目的python环境.用virtualenv 来保持一个干净的环境非常有用. 例如 ...

  8. Salesforce 数据库操作简介

    Salesforce 中的数据库操作方式 Salesforce 为用户和开发者提供了四种基本的数据库操作方式: Apex 中的 DML 语句 Apex 中的 Database 类 SOQL 查询 SO ...

  9. Python 基于urllib.request封装http协议类

    基于urllib.request封装http协议类 by:授客QQ:1033553122 测试环境: Python版本:Python 3.3   代码实践 #!/usr/bin/env python ...

  10. JavaScript非数字(中文)排序

    直接上代码: var arr=[ {name:"张散步",age:"23",sports:"篮球",number:"231123& ...