题意:就是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. Scala构建工具SBT

    SBT(Simple Build Tool)是Scala的项目构建工具,拥有依赖管理,构建过程管理和打包等功能. SBT官网上给出各平台的安装方法: MAC: 使用homebrew安装 brew in ...

  2. es6中的部分新特性

    1.es6中变量声明可以使用let声明变量,用const声明常量.例: test:function(){ { var num=10; let num1=11; const num2=12; } con ...

  3. 玩转物联网之MQTT

    物联网概述 物联网——即Internet-of-Things,其实这个概念由来已久,简单来讲,物联网是物与物.人与物之间的信息传递与控制简称.它和能源.电子信息.医疗.交通.零售.物流.工业制造等行业 ...

  4. Laravel 中使用支付宝、银联支付、微信支付进行支付

    Laravel Packages 为 Laravel 提供了强大的扩展功能,为从 1 到 n 提供无限可能,这其中就包括支付, Laravel 官方提供的 Cashier 包集成对 Stripe 的支 ...

  5. HDU6213

    Chinese Zodiac Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)To ...

  6. Python十讲 - 第一讲:从零开始学Python

    之后慢慢添加... Python语言的背景知识

  7. 正则表达式+XML+反射+设计模式作业

    正则表达式+XML+反射+设计模式作业 一.    填空题 Class.forName('com.bjsxt.stumgr.entity.Student').newInstance( ); 语句的作用 ...

  8. (后端)出现org.hibernate.NonUniqueResultException的原因即解决办法

    百度出来的资料解决问题: 一个问题,事务处理完毕以后页面没有刷新.刚开始以为是前台js的问题,后来检查js没有任何问题,跟踪到后台发现后台报错了,错误信息如下:org.hibernate.NonUni ...

  9. The stacking context

    文档中的层叠上下文由满足以下任意一个条件的元素形成: 1. z-index 值不为 "auto"的 绝对/相对定位. 2. position位fixed. 3. opacity 属 ...

  10. maven(八),阿里云国内镜像,提高jar包下载速度

    镜像 maven默认会从中央仓库下载jar包,这个仓库在国外,而且全世界的人都会从这里下载,所以下载速度肯定是非常慢的.镜像就相当于是中央仓库的一个副本,内容和中央仓库完全一样,目前有不少国内镜像,其 ...