题意:就是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. [NOI 2017]蔬菜

    Description 题库链接 小 N 是蔬菜仓库的管理员,负责设计蔬菜的销售方案. 在蔬菜仓库中,共存放有 \(n\) 种蔬菜,小 N 需要根据不同蔬菜的特性,综合考虑各方面因素,设计合理的销售方 ...

  2. openssl签署和自签署证书的多种实现方式

    openssl系列文章:http://www.cnblogs.com/f-ck-need-u/p/7048359.html 1.采用自定义配置文件的实现方法 1.1 自建CA 自建CA的机制:1.生成 ...

  3. 【Core】创建简单的Core MVC项目

    创建项目: 首先:打开vs选中新建项目- >选中.NET Core - >ASP.NET Core Web应用程序: 然后:在选择web应用程序,注意上面要选中.net Core 别选错了 ...

  4. X问题(中国剩余定理+不互质版应用)hdu1573

    X问题 Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  5. Matlab forward Euler demo

    % forward Euler demo % take two steps in the solution of % dy/dt = y, y(0) = 1 % exact solution is y ...

  6. IOC容器的创建

    一.IOC容器创建方式 Ioc容器的创建时通过ApplicationContext接口的相关实现类进行的. 如上图所示:有三种创建IOC容器的方式. ClassPathXmlApplicationCo ...

  7. 两个inline-block消除间距和对齐(vertical-align)

    一.神奇的两个inline-block 很初级的问题,无聊决定写一个故事. 故事的主人公很简单,两个inline-block元素.代码如下,为了看起来简单明了,写得很简陋.效果图如右.发现有两个问题. ...

  8. Codeforces672D(SummerTrainingDay01-I)

    D. Robin Hood time limit per test:1 second memory limit per test:256 megabytes input:standard input ...

  9. HDU6201

    transaction transaction transaction Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 132768/1 ...

  10. parseInt转换

    function parse2Int(num) { return parseInt(num,10); } 如果 string 以 "0x" 开头,parseInt() 会把 str ...