Codeforces 449C Jzzhu and Apples 贪心 (看题解)
2024-09-01 00:57:26
从大的质因子开始贪心, 如果有偶数个则直接组合, 如果是奇数个留下那个质数的两倍, 其余两两组合。
#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 ;
} /*
*/
最新文章
- js call apply
- WebClient.DownloadFile(线程机制,异步下载文件)
- UVAoj 348 - Optimal Array Multiplication Sequence
- JavaWeb学习笔记——访问静态HTML网页
- iOS - Mac OS X 终端设置
- 12SpringMvc_在业务控制方法中写入普通变量收集参数
- Java SE 第十六讲----方法重载
- (转)如果知道dll文件是面向32位系统还是面向64位系统的?
- AcmeAir
- MyBatis自动获取主键,MyBatis使用Oracle返回主键,Oracle获取主键
- Windows phone 之样式的关联
- Spring mvc基本原理
- Html5模拟通讯录人员排序(sen.js)
- django.db.utils.OperationalError: 1050解决方案
- kickstart无人值守
- MongoDB最佳实践中文手册
- 深挖 NPM 机制
- 不能收缩 ID 为 %s 的数据库中 ID 为 %s 的文件,因为它正由其他进程收缩或为空。
- es索引管理工具-curator
- 事件代理on
热门文章
- vue自学入门-3(vue第一个例子)
- WebAPI跨域处理
- 21. Spring Boot Druid 数据源配置解析
- ASP.NET MVC中的Session设置
- Python中crypto模块进行AES加密和解密
- CentOS6.8配置SonarQube Scanner配合SonarQube使用
- Mybatis进阶学习笔记——动态代理方式开发Dao接口、Dao层(推荐第二种)
- weblogic基本目录介绍,位数查看,启动与发布项目,修改JVM参数,设置项目为默认项目
- sqlldr和sqludr使用笔记
- CSS选择器中带点(.)怎么办?