Jzzhu and Apples

从大的质因子开始贪心, 如果有偶数个则直接组合, 如果是奇数个留下那个质数的两倍, 其余两两组合。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 1e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n;
bool vis[N];
bool prime[N];
queue<int> que;
vector<PII> ans; int main() {
memset(prime, true, sizeof(prime));
prime[] = prime[] = false;
for(int i = ; i < N; i++) {
if(!prime[i]) continue;
for(int j = i * ; j < N; j += i)
prime[j] = false;
}
scanf("%d", &n);
for(int i = n; i >= ; i--) {
if(!prime[i]) continue;
for(int j = * i; j <= n; j += i)
if(!vis[j]) que.push(j);
que.push(i);
if( * i <= n && !vis[ * i]) que.push( * i);
while(SZ(que) >= ) {
int x = que.front(); que.pop();
int y = que.front(); que.pop();
vis[x] = vis[y] = true;
ans.push_back(mk(x, y));
}
while(SZ(que)) que.pop();
}
printf("%d\n", SZ(ans));
for(auto& t : ans) printf("%d %d\n", t.fi, t.se);
puts("");
return ;
} /*
*/

Codeforces 449C Jzzhu and Apples 贪心 (看题解)的更多相关文章

  1. [codeforces] 449C Jzzhu and Apples

    原题 质因数分解后贪心即可(最后贪2) #include<cstdio> #include<vector> #include<stack> #include< ...

  2. Codeforces 229E Gifts 概率dp (看题解)

    Gifts 感觉题解写的就是坨不知道什么东西.. 看得这个题解. #include<bits/stdc++.h> #define LL long long #define LD long ...

  3. Codeforces 1155F Delivery Oligopoly dp(看题解)

    看别人写的才学会的... 我们考虑刚开始的一个点, 然后我们枚举接上去的一条一条链, dp[mask]表示当前已经加进去点的状态是mask所需的最少边数. 反正就是很麻烦的一道题, 让我自己写我是写不 ...

  4. Codeforces 1101F Trucks and Cities dp (看题解)

    Trucks and Cities 一个很显然的做法就是二分然后对于每个车贪心取check, 这肯定会TLE, 感觉会给人一种贪心去写的误导... 感觉有这个误导之后很难往dp那个方向靠.. dp[ ...

  5. Codeforces 380D Sereja and Cinema (看题解)

    Sereja and Cinema 首先我们可以发现除了第一个人, 其他人都会坐在已入坐人的旁边. 难点在于计算方案数.. 我们可以从外往里把确定的人用组合数算上去,然后缩小范围. #include& ...

  6. Codeforces 442D Adam and Tree dp (看题解)

    Adam and Tree 感觉非常巧妙的一题.. 如果对于一个已经建立完成的树, 那么我们可以用dp[ i ]表示染完 i 这棵子树, 并给从fa[ i ] -> i的条边也染色的最少颜色数. ...

  7. Codeforces 915G Coprime Arrays 莫比乌斯反演 (看题解)

    Coprime Arrays 啊,我感觉我更本不会莫比乌斯啊啊啊, 感觉每次都学不会, 我好菜啊. #include<bits/stdc++.h> #define LL long long ...

  8. Codeforces 596D Wilbur and Trees dp (看题解)

    一直在考虑, 每一段的贡献, 没想到这个东西能直接dp..因为所有的h都是一样的. #include<bits/stdc++.h> #define LL long long #define ...

  9. Codeforces 965E Short Code 启发式合并 (看题解)

    Short Code 我的想法是建出字典树, 然后让后面节点最多的点优先向上移到不能移为止, 然后gg. 正确做法是对于当前的节点如果没有被占, 那么从它的子树中选出一个深度最大的点换到当前位置. 用 ...

随机推荐

  1. tomcat运行时为什么不能删除war

    tomcat启动时会监听webapps下的war文件,如果有新增就解压,如果有删除就删除项目

  2. 20. Spring Boot 默认、自定义数据源 、配置多个数据源 jdbcTemplate操作DB

    Spring-Boot-2.0.0-M1版本将默认的数据库连接池从tomcat jdbc pool改为了hikari,这里主要研究下hikari的默认配置 0.  创建Spring Boot项目,选中 ...

  3. MFC中添加了一个dialog,并创建了相应的类,初始化函数没有怎么办?

    1.在头文件中添加  virtual BOOL OnInitDialog();2.在对于的CPP文件中添加  BOOL CXXDlg::OnInitDialog()  {      return TR ...

  4. .net 加密与解密

    public class Encrypts { /// <summary> /// 构造方法 /// </summary> public Encrypts() { } /// ...

  5. 绘图QPainter-画笔

    绘图要在paintEvent()方法中实现.在QPainter对象的begin()与end()方法间编写绘图代码.它会在控件或其他图形设备上进行低级的图形绘制 画笔样式Penstyle Qt.Nope ...

  6. Django 2.0 学习(12):Django 模板语法

    Django 模板语法 一.模板 只要是在html里面有模板语法就不是html文件了,这样的文件就叫做模板. 二.模板语法 模板语法变量:{{ }} 在Django模板中遍历复杂数据结构的关键是句点字 ...

  7. php 获取压缩包名

    参考链接: https://segmentfault.com/q/1010000000721799 通过curl方式获取压缩包名: function getFile($url, $save_dir = ...

  8. More Effective C++ 条款0,1

    More Effective C++ 条款0,1 条款0 关于编译器 不同的编译器支持C++的特性能力不同.有些编译器不支持bool类型,此时可用 enum bool{false, true};枚举类 ...

  9. JXL读取Excel(只支持xls版本)——(二)

    注意:jxl是不支持xlsx后缀的excel的.因此建议用POI读取excel. Jar包 同一一样 Java代码 package JXL; import java.io.File; import j ...

  10. 非常干货之Python资源大全

    非常干货之Python资源大全