Infinite_S's blog

By Infinite_S, history, 4 weeks ago, In English,

My code getting TLE in sgu 112 problem. I am new to java programming so I am not understanding why my code is getting TLE. I also have submitted 3 code from github for this problem. They also got TLE. Now what should I do? Question link : http://codeforces.com/problemsets/acmsguru/problem/99999/112

My code :

//In the name of ALLAH

//package OverRiding;

import java.math.BigInteger;
import java.util.Scanner;

public class Example1 {

    public static void main(String[]args) {


        Scanner cin = new Scanner( System.in );

        BigInteger bigA = cin.nextBigInteger();
        BigInteger bigB = cin.nextBigInteger();
        BigInteger aPowb, bPowa;
        aPowb = bigA.pow ( bigB.intValue() );
        bPowa = bigB.pow ( bigA.intValue() );

        BigInteger ans = aPowb.subtract ( bPowa );
        System.out.println(ans);


    }
}

 
 
 
 

»
4 weeks ago, # |
  Vote: I like it +1 Vote: I do not like it

The Problem is in Scanner, I think. Try use another input class

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    Bro! please tell me about that input class which you have used to solve it. Name or tutorial link.

  • »
    »
    4 weeks ago, # ^ |
      Vote: I like it 0 Vote: I do not like it

    If your Logic is different then tell me the logic.

    • »
      »
      »
      4 weeks ago, # ^ |
        Vote: I like it +1 Vote: I do not like it

      I use bufferedReader and stringtokenizer Don't know if there are some faster way.