关于#python#的问题,请各位专家解答!

就是用0到9这几个数,组成两个三位数和一个四位数,使得两个三位数相加等于那个四位数
这十个数字都要用到并且不能重复
我就简单粗暴的遍历
然后一点点排除
过程那可太,难了
看能不能优化一下下
求佬们指点指点

for a in range(100,1000):
    for b in range(100,1000):
        c = a + b
        if 999 <= c <= 2000:
            a_gewei = a % 10
            a_shiwei = a // 10 % 10
            a_baiwei = a // 100
            
            b_gewei = b % 10
            b_shiwei = b // 10 % 10
            b_baiwei = b // 100
        
            c_gewei = c % 10
            c_shiwei = c // 10 % 10
            c_baiwei = c // 100 % 10
            c_qianwei = c // 1000


            if a_gewei != a_shiwei and c_baiwei != b_baiwei and c_qianwei != b_baiwei and c_baiwei != c_gewei and c_gewei != a_gewei and c_baiwei != a_gewei and c_qianwei != a_shiwei and c_qianwei != a_baiwei and c_qianwei != a_gewei and c_qianwei != c_shiwei and c_baiwei != a_baiwei and c_gewei != a_shiwei and c_baiwei != a_shiwei and c_baiwei != b_shiwei and  c_gewei != c_qianwei and c_gewei != b_shiwei and c_shiwei != a_gewei and a_shiwei != a_baiwei and a_gewei != a_baiwei and a_gewei != b_gewei and a_gewei != b_shiwei and a_gewei != b_baiwei and a_shiwei != b_baiwei and a_baiwei != b_shiwei and a_shiwei != b_shiwei and a_shiwei != c_shiwei and c_gewei != b_baiwei and c_gewei != a_baiwei and c_shiwei != b_baiwei and c_shiwei != a_baiwei and c_shiwei != a_shiwei and c_shiwei != b_shiwei and c_qianwei != b_shiwei and a_baiwei != b_baiwei and a_baiwei != b_gewei and a_shiwei != b_gewei and b_gewei != b_shiwei and b_shiwei != b_baiwei and b_baiwei != b_gewei and b_gewei != c_gewei and b_gewei != c_shiwei and b_gewei != c_baiwei and b_gewei != c_qianwei and c_gewei != c_shiwei and c_shiwei != c_baiwei and c_baiwei != c_qianwei:
                print(f"{c} = {a} + {b}")

https://blog.csdn.net/caolaosanahnu/article/details/14005137