python 多进程爆破代码

版权声明:https://github.com/godspeedcurry 欢迎加好友哦 https://blog.csdn.net/qq_38677814/article/details/86409734
from collections import Counter
import multiprocessing
def decompose_sum(s):
	return [(a,s-a) for a in range(2,int(s/2+1))]
def cal(st,ed,proc):
    print st,ed,proc
    for x in range(st,ed):
	# Generate all possible pairs
	all_pairs = set((a,b) for a in range(2,x+1) for b in range(a+1,x+1))
	
	# Fact 1 --> Select pairs for which all sum decompositions have non-unique product
	product_counts = Counter(c*d for c,d in all_pairs)
	unique_products = set((a,b) for a,b in all_pairs if product_counts[a*b]==1)
	s_pairs = [(a,b) for a,b in all_pairs if
	    all((x,y) not in unique_products for (x,y) in decompose_sum(a+b))]
	 
	# Fact 2 --> Select pairs for which the product is unique
	product_counts = Counter(c*d for c,d in s_pairs)
	p_pairs = [(a,b) for a,b in s_pairs if product_counts[a*b]==1]
	 
	# Fact 3 --> Select pairs for which the sum is unique
	sum_counts = Counter(c+d for c,d in p_pairs)
	final_pairs = [(a,b) for a,b in p_pairs if sum_counts[a+b]==1]
	print(x,proc,final_pairs)
	# multiprocessing多进程
pool = multiprocessing.Pool(processes=10)
for i in range(10):
	pool.apply_async(cal,(i*10+5400,i*10+10+5400,i))
	#传递 函数名 参数
pool.close()
pool.join()

猜你喜欢

转载自blog.csdn.net/qq_38677814/article/details/86409734
今日推荐