Ad
  • Custom User Avatar

    solution is so simple, and I created such a monster, lol

  • Custom User Avatar

    measuring the same way as above, hopefully correctly ( on w3schools.com)

    time in ms: 256

    time in ms: 202

    time in ms: 187

    time in ms: 187

    time in ms: 187

    time in ms: 187

    time in ms: 187

    time in ms: 187

    time in ms: 188

    time in ms: 187

    anyway, I guess now I can see, my solution could be probably more efficient

  • Custom User Avatar

    come on...
    I am measuring the same code on w3schools compiler....
    it gives me less then 100 ms....

    time in ms: 54

    time in ms: 35

    time in ms: 34

    time in ms: 34

    time in ms: 34

    time in ms: 34

    time in ms: 34

    time in ms: 35

    time in ms: 34

    time in ms: 34

    public static void main(String[] args) {

    for (int i = 0; i < 10; i++)
    
    	measureExecutionTime();
    

    }

    public static void measureExecutionTime() {

    long start1 = System.nanoTime();
    
    int n = 14262805;
    
    String f = factors(n);
    
    long start2 = System.nanoTime();
    
    long ms = (start2 - start1)/1_000_000;
    
    System.out.println("time in ms: " +  ms);
    

    }

  • Custom User Avatar

    Execution Timed Out (16000 ms)

    oh, come on.... tests are passed, I just need few millis more....

    it's not hanging forever, anyway...

  • Custom User Avatar

    completely gave up on this one...

  • Custom User Avatar

    This comment is hidden because it contains spoiler information about the solution

  • Custom User Avatar

    by default Math.pow method returns result of type double...

    so there might be truly an error in those tests...

    perhaps method findNb should return double and not long...

  • Custom User Avatar

    it is very interesting it seems that starting from n = 32768

    there are different results for type long (r1) and double (r2)...

    which result is true then...?

    .

    .

    .

    n=32765, r1=288142425153114400, r2=288142425153114400.000000

    n=32766, r1=288177603083145504, r2=288177603083145504.000000

    n=32767, r1=288212784234107168, r2=288212784234107168.000000


    n=32768, r1=288247968606195968, r2=288247968606195970.000000


    n=32769, r1=288283156199608576, r2=288283156199608580.000000

    n=32770, r1=288318347014541568, r2=288318347014541570.000000

    n=32771, r1=288353541051191552, r2=288353541051191550.000000

    n=32772, r1=288388738309755200, r2=288388738309755200.000000
    .
    .
    .

  • Custom User Avatar

    However I still do not understand how it works,

    I added type casting to my previous solution, because, when trying to test failing solution,

    compiler gave me warning,

    but we are summig integers in both cases, so why it does not work...

  • Custom User Avatar
  • Custom User Avatar

    thank you for the tip!

  • Custom User Avatar

    why it's not enough, to check wether list of characters from str1, containsAll characters from str2 ?