Project Euler #134: Prime pair connection

  • + 0 comments

    Can someone tell me what is wrong with this code...? thanks in advance

    n=int(input())
    import math
    for r in range(n):
        a,b=(int(i) for i in input().split())
        l=[]
        for i in range(a,b):
            for j in range(2,int(math.sqrt(b)+1)):
                if i%j==0:
                    break
            else:
                l.append(i)
        for i in range(b,2*b):
            for j in range(2,int(math.sqrt(2*b)+1)):
                if i%j==0:
                    break
            else:
                l.append(i)
                break
        w=0
        for i in range(len(l)-1):
            s,d=str(l[i]),str(l[i+1])
            q=1
            u=0
            while(True):
                k=str(q)+s
                if int(k)%int(d)==0:
                    u=int(k)
                    break
                q+=1
            w+=u
        print(w)