zoukankan      html  css  js  c++  java
  • cf449C Jzzhu and Apples

    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
    ",ans);
    56     for (int i=1;i<=ans;i++)printf("%d %d
    ",ans1[i],ans2[i]);
    57 }
    cf 449C
  • 相关阅读:
    用于爬取知乎某个话题下的精华问题中所有回答的爬虫
    BSP -- 图书共享系统(Book Sharing Platform)
    【已解决】WPS2018 从第三页开始插入页眉页码(即前两页不要页眉页码)
    【编译原理】大白话讲解 First 集和 Follow 集的构造算法
    如果
    HTTP协议(1)------->资源和URL
    JavaWeb框架_Struts2_(八)----->Struts2的国际化
    深入理解java虚拟机----->垃圾收集器与内存分配策略(下)
    深入理解java虚拟机----->垃圾收集器与内存分配策略(上)
    JavaWeb框架_Struts2_(七)----->文件的上传和下载
  • 原文地址:https://www.cnblogs.com/zhber/p/7283775.html
Copyright © 2011-2022 走看看