Help me in TWONUM

Hey Guys,I am getting TLE on a very basic and simple problem(feel bad for that)…I’ve tried the same logic of the code cramped into the main method hopin it would run faster but it took even more.
The Problem TWONUMS.
The original constraints are 1 sec and 50k bytes and the testcases are upto 100.

And somehow my code executes at 0.11 millisec at its best, and considering the codechef stress test(that is it will run the maximum number of testcases)…if i could reduce the execution time to 0.1 it would work.
And i couldnt figure what i can possibly reduce with the code.
Please do comment on my Coding prefrences or in anyway i could improve.
Any critics are highly encouraged.

    import java.util.Scanner;

class Operations extends Game
    //int num_alice,num_bob,turns;
    int result;

    void getData()
        int num_alice = sc_ops.nextInt();
        int num_bob = sc_ops.nextInt();
        int turns = sc_ops.nextInt();

    void gameplay(int num_alice,int num_bob,int turns)
        for(int i=1;i<=turns;i++)

    void result(int num_alice,int num_bob)
        result=(num_alice>num_bob)? (num_alice/num_bob):(num_bob/num_alice);

class Game
{   static Scanner sc_ops= new Scanner(;
    public static void main(String[] args)
        Operations obj = new Operations();
        int cases = sc_ops.nextInt();


Looking at your profile, it appears that you’ve found out how to solve this problem. So this thread can be closed now.

Ya, actually vijju helped me …which basically meant to change my code’s time from O(n) to O(1)…and the same thing helped me in another problem.
Lesson Learnt! :slight_smile: thanks vijju

1 Like