Sort by

recency

|

64 Discussions

|

  • + 0 comments

    Passed all but one test case:

    // Complete the solve function below.
    static String solve(int d, int k) {
            //get integer format of radius
            int r = (int)Math.sqrt(d); 
    
            int count = 0;
    
            //loop for all integer values on X axis
            for(int i = -r; i<r; i++){
    
                    //calculate the float/double value of Y
                    // Let's say, it could be 2.0 or 2.3
                    double y = Math.sqrt(d - i*i);
    
                // convert to INT so it will become either 2.0 in above cases
                    int intY = (int)y;
    
                    //now compare the int version with original version.
                    //if they are same, then Y is also integer and hence we got our point on
                    //the circle. Count is incremented by 2 because, this new point is applicable both above and below x axis.
                    if((float)intY == y ){
                            count+=2;
                    }
    
            }  
            if(k >= count){
                    return "possible";
            } else {
                    return "impossible";
    
        }  
    }
    
  • + 0 comments

    some tese case fail this code .....can you tell why that.....??

    int solve(long int d,long int k) { int r=sqrt(d); int t,p,ans=4; //char *possible,*impossible;

    if((r==1 && k>=4) || (r==2 && k>=4))
            return 1;
    
    
    if(r>2)
    {
    
            p=2,t=2;
            while((r-2)>2 && (r-t)>=2)
            {
                    p=floor((r-t)/2);
                    t=(t+p);
                    ans+=4;
            }
    
    
    }
     if(ans<=k)
                return 1;
            else
                return 0;        
    

    }

  • + 0 comments

    //THis code clear all test cases

    static String solve(int d, int k)

    {
    
        long count=0;
    
        for(long i=0;i<Math.sqrt(d);i++)
    
        {
    
            long p=(long)Math.sqrt((long)d-i*i);
    
            if((p*p+i*i)==d)
    
            {
    
                count+=4;
    
            }
    
        }
    
    
        if(k>=count)
    
        {
    
            return "possible";
    
        }
    
        return "impossible";
    
    }
    
  • + 0 comments

    can anyone help me out... i get TLE on testcase 2. Is my code efficient?

    import math
    t=int(input())
    for _ in range(t):
        d,k=[int(x) for x in input().split()]
        ans=0
        r=math.ceil(d**.5)
        for i in range(0,r):
            x=(d-i**2)**.5
            #y=int(math.sqrt(d-i**2))
            if x==int(x):
                ans+=4
                #print(i,y)
        if k<ans:
            print("impossible")
        else:
            print("possible")
    
  • + 0 comments

    Could be solved easily with https://en.wikipedia.org/wiki/Fermat%27s_theorem_on_sums_of_two_squares and where = number of decompositions of in two squares. The French version of the above page gives this formula and the meaning of and .