Title Link: codeforces 449C jzzhu and Apples
The main idea: Jzzhu from the apple tree to obtain n apples, marking from the 1~n, now they will be two for a group to sell to the merchant, asked for a group of two apples in the number greatest common divisor greater than 1, the number of groups as many as possible.
How to solve the problem: Enumerate the number of conventions D, only enumeration primes, because composite can be enumerated in smaller prime numbers. Take out all the apples that have not been used and are numbered in multiples of D, 22 teams, and if the number is odd, leave 2d. Because D>2, so the 2nd one must be 2d. And 2d is a multiple of 2.
#include <cstdio>#include <cstring>#include <vector>#include <algorithm>using namespace STD;typedefpair<int,int> PII;Const intMAXN =1e5;BOOLiscomp[maxn+5], vis[maxn+5];voidPrime_table (intN) { for(inti =2; I * I <= N; i++) {if(Iscomp[i])Continue; for(intj = i * I; J <= N; J + = i) iscomp[j] =1; }}intMain () {intNscanf("%d", &n); Prime_table (n); vector<int>G vector<pii>Ans for(inti = n/2; i >1; i--) {if(Iscomp[i])Continue; G.clear (); for(intj = i; J <= N; J + = i) {if(Vis[j] = =0) G.push_back (j); }if(G.size () &1) Swap (g[1], g[g.size ()-1]); for(inti =0; I < g.size ()-1; i + =2) {Ans.push_back (Make_pair (g[i), g[i+1])); Vis[g[i]] = vis[g[i+1]] =1; } }printf("%lu\n", Ans.size ()); for(inti =0; I < ans.size (); i++)printf("%d%d\n", Ans[i].first, Ans[i].second);return 0;}
Codeforces 449C Jzzhu and Apples (construction)