Project Euler #216: Investigating the primality of numbers of the form 2n² - 1

  • + 0 comments
    import math
    p=list(map(int,input().split()))
    a=p[0]
    b=p[1]
    c=p[2]
    d=0
    for _ in range(int(input())):
        n=int(input())
        for i in range(0,n+1):
            t=(a*(i**2)+b*(i)+c)
            if t<0:
                t*=(-1)
            if t>=2:
                flag=1
                for j in range(2,int(math.sqrt(t))+1):
                    if t%j==0:
                        flag=0
                        break
                if flag==1:
                    d+=1
        print(d)
        d=0
    

    normal solution