We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. All Contests
  2. ProjectEuler+
  3. Project Euler #207: Integer partition equations
  4. Discussions

Project Euler #207: Integer partition equations

Problem
Submissions
Leaderboard
Discussions

    You are viewing a single comment's thread. Return to all comments →

  • nichuhegde
    8 months ago+ 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);
        }
    }
    

    }

    0|
    Permalink
  • Contest Calendar
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy
  • Request a Feature