【链接】点击打开链接


【题意】


让你选择n个数字,组成一个数组,使得这n个数字中恰好有k对,它们是互质的。

【题解】


我们可以先找出前n个质数,那么接下来的问题就转化为,凑出rest = n*(n-1)/2-k对不互质的数来.
我们先找出最大的t,且满足t*(t-1)/2 <= rest.
这里的t是两两之间都不互质的数的数目.
我们可以把我们取的n个质数中的前t个质数都乘上2.(这里我们取的n个质数要从5开始取)
这样就凑了t*(t-1)/2对不互质的数了.(它们的gcd为2)
接下来处理rest2 = rest-t*(t-1)/2的部分.
我们还是一样,把取的n个质数中的前rest2个质数都乘上3,注意这里rest2是肯定小于等于t的,然后把第t+1个质数也
乘上3.
这样这rest2个数和第t+1个数又是不互质的了.(它们的gcd都为3)
虽然这rest2个数之间也是不互质的.但是这一部分实际上已经和前t个数重合了.
所以,这rest2个不互质的数,已经在前t个质数那里算一遍了
不会重新算一遍.

【错的次数】


0

【反思】


之前已经算过一次,这次不会重新算.
但是可以一个一个填剩余的了
数对问题.
666

【代码】

/*
N在const里面,可以改动;
求出2..N之间的所有质数;
放在zsb数组里面;
时间复杂度是O(N)的;
但是需要空间也是O(N)的;
*/ #include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <cstdlib>
#include <cmath>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x+1)
#define oi(x) printf("%d",x)
#define oc putchar(' ')
#define ol(x) printf("%lld",x)
#define Open() freopen("F:\\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0) typedef pair<int, int> pii;
typedef pair<LL, LL> pll; const int dx[9] = { 0,1,-1,0,0,-1,-1,1,1 };
const int dy[9] = { 0,0,0,-1,1,-1,1,-1,1 };
const double pi = acos(-1.0);
const int N = 2e5;// bool iszs[N + 100];
vector <int> zsb;
int n,k; int main()
{
ms(iszs, true);
rep1(i, 2, N)
{
if (iszs[i]) zsb.pb(i);
int len = zsb.size();
rep1(j, 0, len - 1)
{
int t = zsb[j];
if (i*t>N) break;
iszs[i*t] = false;
if (i%t == 0) break;
}
}
//v[0] = 2,v[1] = 3;
ri(n), ri(k);
k = n*(n - 1) / 2 - k;
int t = 2;
while (t*(t - 1) / 2 <= k) {
t++;
}
t--;
rep1(i, 2, 2 + t - 1)
zsb[i] *= 2;
k = k - t*(t - 1) / 2;
if (k > 0) {
zsb[2 + t] *= 3;
rep1(i, 2, 2 + k - 1) zsb[i] *= 3;
}
rep1(i, 2, 2 + n - 1)
oi(zsb[i]), oc;
return 0;
}

【CS Round #43 E】Coprime Pairs的更多相关文章

  1. 【CS Round #43 D】Bad Triplet

    [链接]点击打开链接 [题意] 给你n个点m条边的无权无向联通图; 让你找3个点A,B,C 使得A->B=B->C=A->C 这里X->Y表示点X到点Y的最短路长度. [题解] ...

  2. 【CS Round #43 C】Rectangle Partition

    [链接]点击打开链接 [题意] 有一辆火车,它的长度为L,然后假设这辆车现在随机可能地出现在0..D之间,然后假设它已经耗光了油. 问你它需要走的期望距离是多少. 这里要走的距离指的是车里最近的加油站 ...

  3. 【CS Round #43 B】Rectangle Partition

    [链接]https://csacademy.com/contest/round-43/task/rectangle-partition/ [题意] 水题 [题解] 横着过去,把相邻的边的宽记录下来. ...

  4. 【CS Round #43 A】Expected Dice

    [链接]https://csacademy.com/contest/round-43/task/expected-dice/ [题意] 大水题 [题解] 把36种可能的结果都存下来. 然后把重复出现的 ...

  5. 【CS round 34】Minimize Max Diff

    [题目链接]:https://csacademy.com/contest/round-34/task/minimize-max-diff/ [题意] 给你n个数字; 数组按顺序不下降; 让你删掉k个数 ...

  6. 【CS Round 34】Max Or Subarray

    [题目链接]:https://csacademy.com/contest/round-34/summary/ [题意] 让你找一个最短的连续子串; 使得这个子串里面所有数字or起来最大; [题解] 对 ...

  7. 【CS Round #36 (Div. 2 only) A】Bicycle Rental

    [题目链接]:https://csacademy.com/contest/round-36/task/bicycle-rental/ [题意] 让你从n辆车中选一辆车; 每一辆车有3个属性 1.到达车 ...

  8. 【CS Round #37 (Div. 2 only) D】Reconstruct Graph

    [Link]:https://csacademy.com/contest/round-37/task/reconstruct-graph/statement/ [Description] 给你一张图; ...

  9. 【CS Round #37 (Div. 2 only) B】Group Split

    [Link]:https://csacademy.com/contest/round-37/task/group-split/ [Description] 让你把一个数分成两个数a.b的和; (a,b ...

随机推荐

  1. OpenJDK源码研究笔记(十四):三种经典的设计方法,接口,接口-抽象类-具体实现类,接口-具体实现类

    在研究OpenJDK源码过程中,我发现常用的设计方法就是2种:接口,接口-抽象类-具体实现类 . 在一些其它开源框架和业务开发中,经常存在着第3种设计,接口-具体实现类. 1.只有接口,没有实现类. ...

  2. 研究一些复杂java开源软件代码的体会(转)

    原文地址:http://herman-liu76.iteye.com/blog/2349026     有时候看源代码是非常有趣的事情,象是思考游戏,象是思考棋局...     平时做J2EE项目中, ...

  3. Linux系统消息队列框架Kafka单机安装配置

    http://www.ithao123.cn/content-11128587.html

  4. C# ArcGIS Engine 线打断

    /// <summary> /// 打断线,用于在点击点处,打断该条线 /// </summary> /// <param name="t_pLineFeatu ...

  5. [Python] Reuse Code in Multiple Projects with Python Modules

    A module is a function extracted to a file. This allows you to import the function and use it in any ...

  6. RTSP传输协议之Methods总结

    RTSP/1.0 200 OK Server: DSS/5.5.5 (Build/489.16; Platform/Linux; Release/Darwin; state/beta; ) Cseq: ...

  7. Web跨域问题基础

    同源策略(Same origin policy)是一种约定,它是浏览器最核心也最基本的安全功能,如果缺少了同源策略,则浏览器的正常功能可能都会受到影响.可以说Web是构建在同源策略基础之上的,浏览器只 ...

  8. Android Retrofit+RxJava 优雅的处理服务器返回异常、错误

    标签: 开始本博客之前,请先阅读: Retrofit请求数据对错误以及网络异常的处理 异常&错误 实际开发经常有这种情况,比如登录请求,接口返回的 信息包括请求返回的状态:失败还是成功,错误码 ...

  9. C/C++(基础-运算符详解)

    运算符 任何表达式是有值的 int a = 2; int b = 3; a*=b+4;//a=a*(b+4);"*"*=的优先级层次和=号的层次一样. printf("% ...

  10. Java生产者与消费者(下)

    本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 上一讲我们让消费者和生产者都各停1毫秒,实际上大多并不是这样的.第二讲,我们讲一个极端的例子和一个正 ...