zhber
有好多做过的题没写下来,如果我还能记得就补吧
随笔 - 501,  文章 - 0,  评论 - 18,  阅读 - 13万

Jzzhu has picked n apples from his big apple tree. All the apples are numbered from 1 to n. Now he wants to sell them to an apple store.

Jzzhu will pack his apples into groups and then sell them. Each group must contain two apples, and the greatest common divisor of numbers of the apples in each group must be greater than 1. Of course, each apple can be part of at most one group.

Jzzhu wonders how to get the maximum possible number of groups. Can you help him?

Input

A single integer n (1 ≤ n ≤ 105), the number of the apples.

Output

The first line must contain a single integer m, representing the maximum number of groups he can get. Each of the next m lines must contain two integers — the numbers of apples in the current group.

If there are several optimal answers you can print any of them.

Examples
Input
6
Output
2
6 3
2 4
Input
9
Output
3
9 3
2 4
6 8
Input
2
Output
0

 

瞎鸡儿构造题是坠猥琐的

枚举  除了2以外  的每个质数p,然后枚举它的倍数,看看其中还没被找过的数有多少个。找完的要用什么东西标记下,防止15=3*5这样的被3,5找两次

如果是偶数个,刚好配好了。如果是奇数个,那么把2p提出来,其他的配对。这样提出来好多个2p[i],他们两两之间都有gcd=2,都可以任意配对。

复制代码
 1 #include<cstdio>
 2 #include<iostream>
 3 #include<cstring>
 4 #include<cstdlib>
 5 #include<algorithm>
 6 #include<cmath>
 7 #include<queue>
 8 #include<deque>
 9 #include<set>
10 #include<map>
11 #include<ctime>
12 #define LL long long
13 #define inf 0x7ffffff
14 #define pa pair<int,int>
15 #define mkp(a,b) make_pair(a,b)
16 #define pi 3.1415926535897932384626433832795028841971
17 using namespace std;
18 inline LL read()
19 {
20     LL x=0,f=1;char ch=getchar();
21     while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
22     while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
23     return x*f;
24 }
25 int n;
26 bool mrk[300010];
27 int res[300010],len;
28 int ans1[300010],ans2[300010],ans;
29 int main()
30 {
31     n=read();
32     for (int i=3;i<=n;i++)
33     {
34         if (!mrk[i]&&(i&1))
35         {
36             int rec=i;
37             for (int j=3*i;j<=n;j+=i)
38             {
39                 if (!mrk[j])
40                 {
41                     if (rec){mrk[rec]=mrk[j]=1;ans1[++ans]=rec;ans2[ans]=j;rec=0;}
42                     else rec=j;
43                 }
44             }
45             if (rec&&!mrk[2*i]&&2*i<=n){mrk[rec]=mrk[2*i]=1;ans1[++ans]=rec;ans2[ans]=2*i;rec=0;}
46             else if (2*i<=n)res[++len]=2*i,mrk[2*i]=1;
47         }
48     }
49     for (int i=2;i<=n;i+=2)
50     {
51         if (!mrk[i])res[++len]=i;
52     }
53     if (len&1)len--;
54     for (int i=1;i<=len;i+=2)ans1[++ans]=res[i],ans2[ans]=res[i+1];
55     printf("%d\n",ans);
56     for (int i=1;i<=ans;i++)printf("%d %d\n",ans1[i],ans2[i]);
57 }
cf 449C
复制代码

 

posted on   zhber  阅读(228)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core GC压缩(compact_phase)底层原理浅谈
· 现代计算机视觉入门之:什么是图片特征编码
· .NET 9 new features-C#13新的锁类型和语义
· Linux系统下SQL Server数据库镜像配置全流程详解
· 现代计算机视觉入门之:什么是视频
阅读排行:
· Sdcb Chats 技术博客:数据库 ID 选型的曲折之路 - 从 Guid 到自增 ID,再到
· 99%的人不知道,桥接模式失败的真正原因是它!
· .NET Core GC压缩(compact_phase)底层原理浅谈
· Winform-耗时操作导致界面渲染滞后
· Phi小模型开发教程:C#使用本地模型Phi视觉模型分析图像,实现图片分类、搜索等功能

< 2025年1月 >
29 30 31 1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31 1
2 3 4 5 6 7 8
点击右上角即可分享
微信分享提示