题目链接-H.Harder Gcd Problem
题目大意
集合和都是集合的子集,且。问和最多有多少对数满足
解题思路
附上代码
//#pragma GCC optimize("-Ofast","-funroll-all-loops")
#include<bits/stdc++.h>
#define int long long
#define lowbit(x) (x &(-x))
#define endl '\n'
using namespace std;
const int INF=0x3f3f3f3f;
const int dir[4][2]={-1,0,1,0,0,-1,0,1};
const double PI=acos(-1.0);
const double e=exp(1.0);
const double eps=1e-10;
const int M=1e9+7;
const int N=2e5+10;
typedef long long ll;
typedef pair<int,int> PII;
typedef unsigned long long ull;
int a[N],b[N];
void pre(){
for(int i=2;i<=N;i++){
if(!b[i]){
for(int j=2*i;j<=N;j+=i)
b[j]=1;
}
}
}
signed main(){
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
int t;
pre();
cin>>t;
while(t--){
int n,ans=0;
cin>>n;
for(int i=2;i<=n;i++)
a[i]=0;
for(int i=n/2;i>=2;i--){
if(!b[i]){
int x=i;
for(int j=n/i*i;j>i;j-=i){
if(a[j]) continue;
if(x==0) x=j;
else{
ans++;
a[x]=j;
a[j]=x;
x=0;
}
}
}
}
cout<<ans<<endl;
for(int i=2;i<=n;i++)
if(a[i]>i)
cout<<i<<" "<<a[i]<<endl;
}
return 0;
}
本文地址:https://blog.csdn.net/Fiveneves/article/details/107573026
如对本文有疑问, 点击进行留言回复!!
两种方法 更改jupyter notebook的打开路径/默认工作路径
RobotFramework接口自动化-全局变量解决保持登录问题
mysql中如何实现 row_number分组求topN的功能
SQLSERVER中RANK OVER(PARTITION BY)的用法
网友评论