Project Euler #170: Find the largest 0 to 9 pandigital that can be formed by concatenating products.

  • + 0 comments

    t=int(input()) n=int(input())

    main=['0','1','2','3','4','5','6','7','8','9']

    for i in range(1,10): for j in range(1,n): for k in range(1,n):

            si=str(i)
            sj=str(j)
            sk=str(k)
            sss=si+sj+sk
            if len(sss)==10:
                list=[]
                list.append(sss[0])
                stor=False
                for p in sss:
                    stor=False
                    for q in list:
                        if q==p:
                            stor=True
                    if not stor:
                        list.append(p)
                list=sorted(list)
    
                if list==main:
    
                    s=str(i*j)
                    s1=str(i*k)
                    st=s+s1
                    if len(st)==10:
    
                        n1=[]
                        n1.append(st[0])
                        sto=False
                        for l in st:
                            sto=False
                            for m in n1:
                                if m==l:
                                    sto=True
                            if not sto:
                                n1.append(l)
                        n1=sorted(n1)
    
    
                        if n1==main:
    
                            print(i,'*(',j,",",k,")=",st,sep='')