cf449C Jzzhu and Apples

本文解析了一道关于将编号苹果进行最优分组的问题。通过枚举质数及其倍数来实现苹果的有效配对,确保每组苹果编号的最大公约数大于1。文中提供了解决方案并附带代码实现。

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

 

转载于:https://www.cnblogs.com/zhber/p/7283775.html

标题基于Python的自主学习系统后端设计与实现AI更换标题第1章引言介绍自主学习系统的研究背景、意义、现状以及本文的研究方法和创新点。1.1研究背景与意义阐述自主学习系统在教育技术领域的重要性和应用价值。1.2国内外研究现状分析国内外在自主学习系统后端技术方面的研究进展。1.3研究方法与创新点概述本文采用Python技术栈的设计方法和系统创新点。第2章相关理论与技术总结自主学习系统后端开发的相关理论和技术基础。2.1自主学习系统理论阐述自主学习系统的定义、特征和理论基础。2.2Python后端技术栈介绍DjangoFlask等Python后端框架及其适用场景。2.3数据库技术讨论关系型和非关系型数据库在系统中的应用方案。第3章系统设计与实现详细介绍自主学习系统后端的设计方案和实现过程。3.1系统架构设计提出基于微服务的系统架构设计方案。3.2核心模块设计详细说明用户管理、学习资源管理、进度跟踪等核心模块设计。3.3关键技术实现阐述个性化推荐算法、学习行为分析等关键技术的实现。第4章系统测试与评估对系统进行功能测试和性能评估。4.1测试环境与方法介绍测试环境配置和采用的测试方法。4.2功能测试结果展示各功能模块的测试结果和问题修复情况。4.3性能评估分析分析系统在高并发等场景下的性能表现。第5章结论与展望总结研究成果并提出未来改进方向。5.1研究结论概括系统设计的主要成果和技术创新。5.2未来展望指出系统局限性并提出后续优化方向。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值