Project Euler #207: Integer partition equations

  • + 0 comments

    i am getting timeout:

    import java.io.; import java.util.; import java.text.; import java.math.; import java.util.regex.*;

    public class Solution {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int q = in.nextInt();
        int a;
        int b;
        double abratio;
        int m;
        int perfectpartition;
        int totalpartition;
        double pmratio;
        double discriminant;
        double t;
        double t4;
        double t2;
        for(int i=0;i<q;i++){
            a=in.nextInt();
            b=in.nextInt();
            abratio = (double)a/b;
            m=2;
            totalpartition=0;
            perfectpartition=0;
            for(int k=1;k<=m;k++){
                discriminant = 1+4*k;
                t=Math.log((1+Math.sqrt(discriminant))/2)/Math.log(2);
                t4=Math.round(Math.pow(4,t)*1000000d)/1000000d;
                t2=Math.round(Math.pow(2,t)*1000000d)/1000000d;;
                if(t4==(int)t4 && t2==(int)t2){
                    totalpartition++;
                    if(Math.round(t*1000000d)/1000000d==(int)t)
                        perfectpartition++;
                }   
                pmratio=(double)perfectpartition/totalpartition;
                if(pmratio<abratio) break;
                else m++;
            }
            System.out.println(m-1);
        }
    }
    

    }