All pastes #1215038 Raw Edit

Stuff

public java v1 · immutable
#1215038 ·published 2008-09-30 20:11 UTC
rendered paste body
public class Problem27 {   public static boolean isPrime(int num) {      for(int i=2;i*i<=num;i++) {         if(num % i == 0) {            return false;         }      }      return true;   }      public static void main(String[] args) {      int maxConsec = 0;      int besta = 0;      int bestb = 0;      for(int i=-999;i<999;i++) { //a         for(int j=-999;j<999;j++) { //b            int n = 0;            int consec = 0;            while(isPrime(n*n + i*n + j)) {               consec++;               n++;            }            if(consec > maxConsec) {               maxConsec = consec;               besta = i;               bestb = j;            }         }      }      System.out.println("a="+besta+", b="+bestb+" gave "+maxConsec+" consecutive primes");      System.out.println("Result: "+besta*bestb);   }}