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.
usingSystem;usingSystem.Collections.Generic;usingSystem.IO;usingSystem.Linq;classSolution{staticvoidMain(String[]args){int[]products=newint[30001];//we store repeated inputs hereintt=Convert.ToInt32(Console.ReadLine());for(inta0=0;a0<t;a0++){intn=Convert.ToInt32(Console.ReadLine());intproduct;if(products[n]==0){products[n]=-1;product=-1;for(intc=n/3;c<=n/2;c++){for(intb=1;b<c;b++){inta=n-c-b;if(a<=b)//we want a <= b < c{if(a*a+b*b==c*c){if(a*b*c>product){product=a*b*c;products[n]=product;}}}}}}Console.WriteLine(products[n]);}}}
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #9: Special Pythagorean triplet
You are viewing a single comment's thread. Return to all comments →
Maybe it can still be optimized: