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. springboot(八)自定义Filter、自定义Property

    自定义Filter 我们常常在项目中会使用filters用于录调用日志.排除有XSS威胁的字符.执行权限验证等等. Spring Boot自动添加了OrderedCharacterEncodingFi ...

  2. Java——关于num++和++num

    public class num_add_add { public static void numAdd(){ int num = 10; int a = num++; System.out.prin ...

  3. 20155231 2016-2017-2 《Java程序设计》第6周学习总结

    20155231 2016-2017-2 <Java程序设计>第6周学习总结 教材学习内容总结 学习目标 理解流与IO 理解InputStream/OutPutStream的继承架构 理解 ...

  4. cmd 命令 添加端口

    cmd 添加端口:netsh firewall add portopening tcp 45625 "telnet"

  5. luogu P4160 [SCOI2009]生日快乐

    传送门 考虑因为每个人的蛋糕体积要相等,如果切了一刀,那么要使得分当前蛋糕的人根据分成的两部分蛋糕的体积分成两部分人,所以假设当前有n人,切的这一刀要是在x或y的\(\frac{k}{n}(k\in ...

  6. luogu P1762 偶数

    打表找规律吼题哇 首先打出\(1-1000\)内的答案的表 0 0 1 1 4 6 9 9 16 ... 448363 ~~有个**规律啊qwq~~ 然后想到用\(\frac{n(n+1)}{2}\) ...

  7. Ajax跨域访问解决方案

    No 'Access-Control-Allow-Origin' header is present on the requested resource. 当使用ajax访问远程服务器时,请求失败,浏 ...

  8. Spring Boot 多模块项目创建与配置 (一) (转)

    Spring Boot 多模块项目创建与配置 (一) 最近在负责的是一个比较复杂项目,模块很多,代码中的二级模块就有9个,部分二级模块下面还分了多个模块.代码中的多模块是用maven管理的,每个模块都 ...

  9. Python 对图片进行人脸识别

    import cv2 def detect(path): img = cv2.imread(path) cascade = cv2.CascadeClassifier("/vagrant/d ...

  10. 【转】C/C++内存泄漏及检测

    “该死系统存在内存泄漏问题”,项目中由于各方面因素,总是有人抱怨存在内存泄漏,系统长时间运行之后,可用内存越来越少,甚至导致了某些服务失败.内存泄漏是最难发现的常见错误之一,因为除非用完内存或调用ma ...