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 ;
} /*
*/

最新文章

  1. js call apply
  2. WebClient.DownloadFile(线程机制,异步下载文件)
  3. UVAoj 348 - Optimal Array Multiplication Sequence
  4. JavaWeb学习笔记——访问静态HTML网页
  5. iOS - Mac OS X 终端设置
  6. 12SpringMvc_在业务控制方法中写入普通变量收集参数
  7. Java SE 第十六讲----方法重载
  8. (转)如果知道dll文件是面向32位系统还是面向64位系统的?
  9. AcmeAir
  10. MyBatis自动获取主键,MyBatis使用Oracle返回主键,Oracle获取主键
  11. Windows phone 之样式的关联
  12. Spring mvc基本原理
  13. Html5模拟通讯录人员排序(sen.js)
  14. django.db.utils.OperationalError: 1050解决方案
  15. kickstart无人值守
  16. MongoDB最佳实践中文手册
  17. 深挖 NPM 机制
  18. 不能收缩 ID 为 %s 的数据库中 ID 为 %s 的文件,因为它正由其他进程收缩或为空。
  19. es索引管理工具-curator
  20. 事件代理on

热门文章

  1. vue自学入门-3(vue第一个例子)
  2. WebAPI跨域处理
  3. 21. Spring Boot Druid 数据源配置解析
  4. ASP.NET MVC中的Session设置
  5. Python中crypto模块进行AES加密和解密
  6. CentOS6.8配置SonarQube Scanner配合SonarQube使用
  7. Mybatis进阶学习笔记——动态代理方式开发Dao接口、Dao层(推荐第二种)
  8. weblogic基本目录介绍,位数查看,启动与发布项目,修改JVM参数,设置项目为默认项目
  9. sqlldr和sqludr使用笔记
  10. CSS选择器中带点(.)怎么办?