[nowcoder5669H]Harder Gcd Problem

1 #include<bits/stdc++.h>
2 using namespace std;
3 #define N 200005
4 vector<int>v,ans[N];
5 int E,t,n,p[N],mn[N],vis[N],bl[N];
6 int main(){
7 for(int i=2;i<N-4;i++){
8 if (!vis[i]){
9 p[++p[0]]=i;
10 mn[i]=i;
11 }
12 for(int j=1;(j<=p[0])&&(i*p[j]<N-4);j++){
13 vis[i*p[j]]=1;
14 mn[i*p[j]]=p[j];
15 if (i%p[j]==0)break;
16 }
17 }
18 scanf("%d",&t);
19 while (t--){
20 scanf("%d",&n);
21 for(int i=1;i<=n;i++)vis[i]=0;
22 for(int i=2;i<=n;i++){
23 vis[mn[i]]++;
24 bl[i]=mn[i];
25 }
26 for(int i=1;(i<=p[0])&&(p[i]<=n);i++)
27 if ((vis[p[i]]&1)&&(p[i]<=n/2))bl[2*p[i]]=p[i];
28 for(int i=1;i<=n;i++)ans[i].clear();
29 for(int i=2;i<=n;i++)ans[bl[i]].push_back(i);
30 int sum=0;
31 for(int i=2;i<=n;i++)sum+=ans[i].size()/2;
32 printf("%d\n",sum);
33 for(int i=1;(i<=p[0])&&(p[i]<=n);i++)
34 for(int j=0;j+1<ans[p[i]].size();j+=2)printf("%d %d\n",ans[p[i]][j],ans[p[i]][j+1]);
35 }
36 }
[nowcoder5669H]Harder Gcd Problem的更多相关文章
- 【算法系列学习】codeforces C. Mike and gcd problem
C. Mike and gcd problem http://www.cnblogs.com/BBBob/p/6746721.html #include<iostream> #includ ...
- CF798 C. Mike and gcd problem
/* CF798 C. Mike and gcd problem http://codeforces.com/contest/798/problem/C 数论 贪心 题意:如果一个数列的gcd值大于1 ...
- Codeforces Round #410 (Div. 2)C. Mike and gcd problem
题目连接:http://codeforces.com/contest/798/problem/C C. Mike and gcd problem time limit per test 2 secon ...
- codeforces#410C Mike and gcd problem
题目:Mike and gcd problem 题意:给一个序列a1到an ,如果gcd(a1,a2,...an)≠1,给一种操作,可以使ai和ai+1分别变为(ai+ai+1)和(ai-ai+1); ...
- Codeforces 798C. Mike and gcd problem 模拟构造 数组gcd大于1
C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: s ...
- #410div2C. Mike and gcd problem
C. Mike and gcd problem time limit per test 2 seconds memory limit per test 256 megabytes input stan ...
- Codeforces 798C - Mike and gcd problem(贪心+数论)
题目链接:http://codeforces.com/problemset/problem/798/C 题意:给你n个数,a1,a2,....an.要使得gcd(a1,a2,....an)>1, ...
- FZU 2224 An exciting GCD problem(GCD种类预处理+树状数组维护)同hdu5869
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2224 同hdu5869 //#pragma comment(linker, "/STACK:1024 ...
- 【codeforces 798C】Mike and gcd problem
[题目链接]:http://codeforces.com/contest/798/problem/C [题意] 给你n个数字; 要求你进行若干次操作; 每次操作对第i和第i+1个位置的数字进行; 将 ...
随机推荐
- 学习使用SignalR
1.创建空白的控制台程序 2.添加两个NuGet包(Microsoft.AspNet.SignalR.SelfHost.Microsoft.Owin.Cors.Topshelf)Topshelf用于快 ...
- THUSC & 中考 & NOI 拉跨记
THUSC 的拉胯记 时代比较久远了,可能有些事情记不清楚了. Day -\(\infty\) 本来说只有我.llsw.wxk过了审核,后来wy.lyc也搞了个体验营名额,于是和高二的一起集训. Da ...
- 洛谷2120 [ZJOI2007]仓库建设(斜率优化dp)
感觉和锯木厂那个题很类似的. 其实这个题还那个题唯一的区别就是\(dp\)转移式子中的\(f\)变成了\(g\) qwq不想多说了 直接看我的前一篇题解吧qwq #include<iostrea ...
- python单例模式设计
class MyTest(): my_obj = None def __new__(cls,*args,**kwargs): if not cls.my_obj: cls.my_obj =object ...
- 【UE4 C++】打印字符串与输出日志
打印屏幕 默认打印屏幕 // 打印至屏幕 FString screenMessage = "(AddOnScreenDebugMessage) Hello world!"; GEn ...
- SpringCloud微服务实战——搭建企业级开发框架(五):数据库持久化集成MySql+Druid+MyBatis-Plus
在引入相关数据库持久化相关依赖库之前,我们可以考虑到,当我们因业务开发需要,引入各种各样的依赖库时,Jar包冲突是我们必须面对的一个问题,Spring为了解决这些Jar包的冲突,推出了各种bom, ...
- OO2020 助教工作总结
1 我的初衷 这一学期的OO助教工作是我一段宝贵的经历,在其中我学习了很多.见识了很多,收获满满.当时报名OO的初衷主要有三方面.首先,我想说OO是我所上过的最好的一门课之一,这门课有这一套从理论讲授 ...
- 『学了就忘』Linux基础 — 11、通过setup工具配置Linux系统IP地址
目录 1.setup命令介绍 2.使用setup命令配置IP (1)执行setup命令 (2)进入图形化配置界面 (3)选择配置IP还是DNS (4)选择要配置的网卡 (5)进入IP地址配置页面 (6 ...
- 把二叉树打印成多行 牛客网 剑指Offer
把二叉树打印成多行 牛客网 剑指Offer 题目描述 从上到下按层打印二叉树,同一层结点从左至右输出.每一层输出一行 # class TreeNode: # def __init__(self, x) ...
- filter tools
// 过滤商品分类 Vue.filter("cateFilter", (data) => { let tmp = ["一级分类", "二级分 ...