We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
this is the happy_coder solution in python ,to those interested in the python version of the solution
importmathdefmain():numberOfTestCases=int(input())generatePrimes()foriinrange(numberOfTestCases):res=0n=int(input())forjinrange(2,n+1):ifprime[j]:diff=n-jifdiff%2==0andisPerfectSquare(diff//2):res+=1print(res)defisPerfectSquare(input):root=int(math.sqrt(input))returninput==root*rootdefgeneratePrimes():limit=1000000globalprimeprime=[False]*(limit+1)prime[2]=Trueprime[3]=Trueroot=int(math.ceil(math.sqrt(limit)))# Sieve of Atkin for prime number generationforxinrange(1,root):foryinrange(1,root):n=4*x*x+y*yifn<=limitand(n%12==1orn%12==5):prime[n]=notprime[n]n=3*x*x+y*yifn<=limitandn%12==7:prime[n]=notprime[n]n=3*x*x-y*yifx>yandn<=limitandn%12==11:prime[n]=notprime[n]foriinrange(5,root):ifprime[i]:forjinrange(i*i,limit,i*i):prime[j]=Falseif__name__=="__main__":main()
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
An unexpected error occurred. Please try reloading the page. If problem persists, please contact support@hackerrank.com
Project Euler #46: Goldbach's other conjecture
You are viewing a single comment's thread. Return to all comments →
this is the happy_coder solution in python ,to those interested in the python version of the solution