Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class AbcdSquaredEqualThousand {
- public static void main(String[] args) {
- long tempLong = System.currentTimeMillis();
- doUnoptimised();
- System.out.println("MS Taken:" + (System.currentTimeMillis() - tempLong));
- tempLong = System.currentTimeMillis();
- doFirstOptimised();
- System.out.println("MS Taken:" + (System.currentTimeMillis() - tempLong));
- }
- public static void doUnoptimised() {
- for(int a = 1; a < 100; a++)
- {
- for(int b = 1; b < 100; b++)
- {
- for(int c = 1; c < 100; c++)
- {
- for(int d = 1; d < 100; d++) {
- if(Math.pow(a, 3) + Math.pow(b, 3) == Math.pow(c, 3) + Math.pow(d, 3))
- {
- System.out.println("A:" + a + " B:" + b + " C:" + c + " D:" + d);
- }
- }
- }
- }
- }
- }
- public static void doFirstOptimised() {
- for(int a = 1; a < 100; a++)
- {
- for(int b = 1; b < 100; b++)
- {
- for(int c = 1; c < 100; c++)
- {
- for(int d = 1; d < 100; d++) {
- if(Math.pow(a, 3) + Math.pow(b, 3) == Math.pow(c, 3) + Math.pow(d, 3))
- {
- System.out.println("A:" + a + " B:" + b + " C:" + c + " D:" + d);
- break;
- }
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement