Mashmokh and Numbers CodeForces - 415C
题意:就是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的更多相关文章
- 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 ...
- Magic Numbers CodeForces - 628D
Magic Numbers CodeForces - 628D dp函数中:pos表示当前处理到从前向后的第i位(从1开始编号),remain表示处理到当前位为止共产生了除以m的余数remain. 不 ...
- 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 ...
- Really Big Numbers CodeForces - 817C (数学规律+二分)
C. Really Big Numbers time limit per test 1 second memory limit per test 256 megabytes input standar ...
- 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> # ...
- AC日记——Little Elephant and Numbers codeforces 221b
221B - Little Elephant and Numbers 思路: 水题: 代码: #include <cmath> #include <cstdio> #inclu ...
- 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 ...
- Dividing the numbers CodeForces - 899C (构造)
大意: 求将[1,n]划分成两个集合, 且两集合的和的差尽量小. 和/2为偶数最小差一定为0, 和/2为奇数一定为1. 显然可以通过某个前缀和删去一个数得到. #include <iostrea ...
随机推荐
- N最短路径分词
N最短路径算法是一种基于词典的分词算法. 每个句子将生成一个有向无环图, 每个字作为图的一个定点, 边代表可能的分词. 在上图中, 边的起点为词的第一个字, 边的终点为词尾的下一个字. 边1表示&qu ...
- rootkit(kbeast-v1)
Rootkit有应用级.内核级和硬件级 用的比较多的是内核级别,比如基于linux LKM编写的rootkit rootkit可以理解为一个超级管理员的工具箱,这个工具箱通过调用系统LKM接口可以动态 ...
- SqlServer 登录和卸载
一.数据库简介 SQLServer环境配置 安装好数据库以后怎么启用sa账号来访问数据库. 1.先用windows账号登录数据库. 2.启用windows身份验证方式和sql server身份验证方式 ...
- Git 实战手册(一): 批量修改log中的提交信息
本文须知 教程所示图片使用的是 github 仓库图片,网速过慢的朋友请移步原文地址 有空就来看看个人技术小站, 我一直都在 背景介绍 事情的起源是这样的:迷恋的谷歌的我最近申请了一个新的 googl ...
- git常用命令以及如何与fork别人的仓库保持同步
简单常用命令1.git status查看当前仓库是否有文件改动a:提示Your branch is up-to-date with 'origin/master'.nothing to commit, ...
- mac 上运行httpserver的问题
如果你的系统是window 我建议你安装http-server 非常好用, 如果是mac,系统自带的就有httpserver 服务,没有必要在安装 按照我说的来操作 首先 sudo apachectl ...
- 微信小程序日历课表
最近项目中使用到了日历,在网上找了一些参考,自己改改,先看效果图 wxml <view class="date"> <image class="dire ...
- 可视化接口管理工具RAP,模拟数据,校验接口
最近看到一个不错的接口管理的工具,分享一下 RAP ppt介绍:http://www.imooc.com/video/11060 RAP是一个可视化接口管理工具 通过分析接口结构,动态生成模拟数据,校 ...
- IDEA项目搭建八——使用MybatisPlus简化数据库交互
一.MybatisPlus简化数据库交互 我们使用Mybatis发现需要在mapper.xml中写很多重复的简单CRUD(增删改查),使用MybatisPlus可以大大简化这部分代码,官方文档http ...
- Linux 学习笔记之超详细基础linux命令 Part 6
Linux学习笔记之超详细基础linux命令 by:授客 QQ:1033553122 ---------------------------------接Part 5----------------- ...