primepairsets

#include<bits/stdc++.h>

using namespace std;
#define int long long 

vector<int> p;
bool vis[1000005];
int f[1000005];
bool is[1000005];
bool g[2000][2000]; 
int n;

int get (string s) {
	int num = 0;
	for (auto t : s)
		num = num * 10 + t - '0';
	return num;
}
bool check (int tar) {
	for (int i = 2; i <= tar / i; i ++)
		if (tar % i==0) return 0;
	return 1;
}

void init() {
	
	for (int i = 2; i <= 1000000; i ++) {
		if (!vis[i]) {
			p.push_back(i); 
			is[i] = 1;
		}
		for (int j = 0; p[j] * i <= 1000000; j ++) {
			vis[p[j] * i] = 1;
			if (i % p[j] == 0)  break;
		}
	}
}

int ans;
vector<int> v;
bool ck (int i) {
	for (auto t : v)
		if (!g[t][i] || !g[i][t])  return 0;
	return 1;
}
void dfs (int x, int cnt) {
	if (cnt + n - x <= ans) return ;
	ans = max (ans, cnt);
	if (cnt == 5) {
		for (auto t : v) {
			cout << p[t - 1]<< ' ';
		}
		puts("");
	}
	for (int i = x + 1; i <= n; i ++) {
		if (ck(i)) {
			v.push_back(i);
			dfs(i, cnt + 1);
			v.pop_back();
		}
	}
}
signed main () {
	init();
	cout << p.size() << endl;
	for (int i = 0; i < p.size(); i ++)
		vis[i + 1] = p[i];
	
	while(p[n] < 10000)
		n ++;
	
	for (int i = 1; i <= n; i ++) {
		for (int j = 1; j <= n; j ++) {
			if (i == j) continue;
			auto t =  get(to_string(p[i - 1])+ to_string(p[j - 1]));
			if (t % 2 == 0) continue; 
			if (check(t)) {
				g[i][j] = 1;
			}
		
		}
	}

	for (int i = 1; i <= n ;i ++) {
		v.push_back(i);
		dfs(i, 1);
		v.pop_back();
	}
	 cout << ans << endl;
	return 0;
} 

最大团算法

对于加入的点,我们要判断是否与当前所有点连接,如果连接则团数加1,否则不算入

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值