CF449C:Jzzhu and Apples——题解
https://vjudge.net/problem/CodeForces-449C
题目大意:1-n编号的苹果两两一对,他们的最大公约数不为1,求这些对的最大匹配。
————————————————————————————————
我们显然先把素数筛出来。
然后我们从后往前循环素数p,然后p,2p,3p(取过的自动不要)……这些数两两都可以成一对。
但是如果是奇数个,我们就抛掉2p,因为2p一定可以与其他2的倍数一对。
不知道怎么证明……
#include<cstdio>
#include<cstring>
#include<vector>
#include<iostream>
#include<algorithm>
https://vjudge.net/problem/CodeForces-449Cusing namespace std;
typedef long long ll;
const int N=1e5+;
int su[N];
bool he[N];
void Eratosthenes(int n){
for(int i=;i<=n;i++){
if(he[i]!=)continue;
for(int j=;j*i<=n;j++)he[j*i]=;
}
return;
}
vector<int>a;
int p[N][];
bool ok[N];
int main(){
int n;
scanf("%d",&n);
Eratosthenes(n);
int ans=;
for(int i=n/;i>=;i--){
if(he[i])continue;
a.clear();
for(int j=i;j<=n;j+=i){
if(!ok[j]){
a.push_back(j);
}
}
if(a.size()%)swap(a[],a[a.size()-]);
for(int j=;j<a.size()-;j+=){
ans++;
p[ans][]=a[j];ok[a[j]]=;
p[ans][]=a[j+];ok[a[j+]]=;
}
}
printf("%d\n",ans);
for(int i=;i<=ans;i++){
printf("%d %d\n",p[i][],p[i][]);
}
return ;
}
CF449C:Jzzhu and Apples——题解的更多相关文章
- CF449C Jzzhu and Apples (筛素数 数论?
Codeforces Round #257 (Div. 1) C Codeforces Round #257 (Div. 1) E CF450E C. Jzzhu and Apples time li ...
- CF449C Jzzhu and Apples
嘟嘟嘟 这道题正解是怎么对的其实我也不清楚,总之靠感性理解吧. 首先当然要把1到n / 2的素数都筛出来,因为两两能配对的数一定都是这些素数的倍数.这也就说明对于(n / 2, n]的素数,他们一定不 ...
- Codeforces 449C Jzzhu and Apples 贪心 (看题解)
Jzzhu and Apples 从大的质因子开始贪心, 如果有偶数个则直接组合, 如果是奇数个留下那个质数的两倍, 其余两两组合. #include<bits/stdc++.h> #de ...
- CF449 C. Jzzhu and Apples
/* http://codeforces.com/problemset/problem/449/C cf 449 C. Jzzhu and Apples 数论+素数+贪心 */ #include &l ...
- Codeforces Round #257 (Div. 2) E题:Jzzhu and Apples 模拟
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 449.C Jzzhu and Apples
C. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- CF 450E Jzzhu and Apples 数学+模拟
E. Jzzhu and Apples time limit per test 1 second memory limit per test 256 megabytes input standard ...
- Codeforces 450E:Jzzhu and Apples(构造,数学)
E. Jzzhu and Apples time limit per test: 1 seconds memory limit per test: 256 megabytes input: stand ...
- CF449C:Jzzhu and Apples
题意简述 给出正整数n,你要把1-n之间的正整数分成尽可能多组,使得每一组两个数的最大公约数大于1;输出能分成最多组的个数,并按任意顺序输出每组的两个数. 很妙的一道题. 首先我们考虑去处理每个质数的 ...
随机推荐
- android 几个工具方法
集合几个工具方法,方便以后使用. 1.获取手机 分辨率屏幕: public static void printScreenInfor(Context context){ DisplayMetrics ...
- 180608-Git工具之Stash
git stash 暂存 背景: 实际开发过程中,经常可能遇到的一个问题,当你在dev分支上正开发得happy的时候:突然来了个线上bug,得赶紧从release分支上切一个bugfix分支来解决线上 ...
- [转载]CENTOS 6.0 iptables 开放端口80 3306 22端口
原文地址:6.0 iptables 开放端口80 3306 22端口">CENTOS 6.0 iptables 开放端口80 3306 22端口作者:云淡风轻 #/sbin/iptab ...
- UVa 1585 - Score - ACM/ICPC Seoul 2005 解题报告 - C语言
1.题目大意 给出一个由O和X组成的字符串(长度为80以内),每个O的得分为目前连续出现的O的数量,X得分为0,统计得分. 2.思路 实在说不出了,这题没过脑AC的.直接贴代码吧.=_= 3.代码 # ...
- Eclipse安装颜色主题,个性化你的IDE,让你的IDE焕然一新
我们都知道eclipse默认的颜色主题是白色的背景,但是如果想改变代码编辑区的背景颜色,需要怎么办呢? 今天给大家介绍一个非常赞的eclipse,可以很方便的根据自己的需求选择喜欢的颜色主题,其他的不 ...
- 基础数据类型-set
Set是无序不重复元素的序列,基本功能是删除重复元素和测试成员关系, 创建一个集合可以用set()或者({}),但是创建一个空集合只能用set(): s1 = set() print("s1 ...
- POJ 2208 Pyramids(求四面体体积)
Description Recently in Farland, a country in Asia, a famous scientist Mr. Log Archeo has discovered ...
- Alpha发布-----欢迎来怼团队
欢迎来怼项目小组—Alpha发布展示 一.小组成员 队长:田继平 成员:葛美义,王伟东,姜珊,邵朔,冉华 ,李圆圆 二.文案+美工展示 链接:http://www.cnblogs.com/wwd199 ...
- 【IdentityServer4文档】- 支持协议
IdentityServer 实现了以下协议: OpenID Connect OpenID Connect Core 1.0 (spec) OpenID Connect Discovery 1.0 ( ...
- Java常用类之Math类
Java 的常用类Math类: java.lang.Math 提供了系列的静态方法用于科学计算,其方法的参数和返回值类型一般为 double 类型. 如: 1. public static final ...