You are viewing a single comment's thread. Return to all comments →
is there any way to optimize it?
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
int check(long a,long b, long c) { double d=Math.pow(c,0.5); if(d>a) { double r=b*Math.pow(c,0.5); double h=(-1)*(a-r); double i=100*Math.pow(h,1.0/3.0) ; int y=(int)i; double o=(double)y/100; double r1=b*Math.pow(c,0.5); double h1=(a+r); double i1=100*Math.pow(h1,1.0/3.0) ; int y1=(int)i1; double o1=(double)y1/100; if(o1-o==1.0) return 1; else return 0; } else { double r=b*Math.pow(c,0.5); double h=(a-r); double i=100*Math.pow(h,1.0/3.0) ; int y=(int)i; double o=(double)y/100; double r1=b*Math.pow(c,0.5); double h1=(a+r); double i1=100*Math.pow(h1,1.0/3.0) ; int y1=(int)i1; double o1=(double)y1/100; if(o1+o==1.0) return 1; else return 0; } } public static void main (String[] args) throws java.lang.Exception { Scanner sc=new Scanner(System.in); int c=0; int u=sc.nextInt(); long[] f=new long[u]; for(int o=0;o<u;o++) { f[o]=sc.nextInt(); } long n; for(int y=0;y<u;y++) { n=f[y]; for(long i=1;i<n-3;i++) { for(long j=1;j<=n-i;j++) { for(long k=1;k<=n-i-j;k++) { Solution st=new Solution(); if(i+j+k<=n) { if(st.check(i,j,k)==1) { //System.out.println(i+" "+j+" "+k); c++; } } } } } System.out.println(c); } }
}
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #251: Cardano Triplets
You are viewing a single comment's thread. Return to all comments →
is there any way to optimize it?
import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;
public class Solution {
}