Problem 9. Special Pythagorean triplet

import java.lang.Math;

public class euler9 {
    public static void main(String[]args) {
        int b = 0, c = 0;
        for (int i = 1; i < 1000; i++) {
            double j = (-(int)Math.pow(i,2) + 1000*i - 500000.0)/(i-1000.0);
            if (Math.floor(j) == j) {
                c = (int)j;
                b = i;
                if ((1000-b-c) < b)
                     break;
            }
        }
        int a = 1000 - b - c;
        System.out.println(a*b*c);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

*

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>