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.
importjava.util.*;classEuler229{privatebooleanisEuler(finalintNumber){booleanFin=true,unfin[]={false,false,false,false};for(inti=1;i<=Math.sqrt(Number);i++){for(intj=1;j<=Math.sqrt(Number);j++){if(((i*i)+(j*j))==Number){unfin[0]=true;break;}}}for(inti=1;i<=Number/2;i++){for(intj=1;j<=Number/2;j++){if(((i*i)+(2*j*j))==Number){unfin[1]=true;break;}}}for(inti=1;i<=Number/2;i++){for(intj=1;j<=Number/2;j++){if(((i*i)+(3*j*j))==Number){unfin[2]=true;break;}}}for(inti=1;i<=Number/2;i++){for(intj=1;j<=Number/2;j++){if(((i*i)+(7*j*j))==Number){unfin[3]=true;break;}}}//System.out.println(unfin[0]+unfin[1]+unfin[2]);returnunfin[0]&&unfin[1]&&unfin[2]&&unfin[3];}publicstaticvoidmain(String[]args){Scannersc=newScanner(System.in);intq=sc.nextInt();intc=0;Euler229obj=newEuler229();for(inti=1;i<=q;i++){intn=sc.nextInt();for(intj=1;j<=n;j++)if(obj.isEuler(j)){System.out.println("Workin' on it");c++;}System.out.println(c);c=0;}}}
Project Euler #229: Four Representations using Squares
You are viewing a single comment's thread. Return to all comments →
tell if it is wrong