Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 40121

Wrong Answer in Modaks inTrinity(TR004)

$
0
0

What's wrong with my solution ?Here's the link of the problem(link-http://www.codechef.com/TRNT2014/problems/TR004/)

import java.io.BufferedReader;

import java.io.InputStreamReader;

import java.math.BigInteger;

import java.util.StringTokenizer;

class Modaks {

/**
 * @param args the command line arguments
 */

public static BigInteger BP(BigInteger A,BigInteger B,BigInteger MOD)
{
    BigInteger R=BigInteger.ONE;
    BigInteger S=A;
    while(B.compareTo(BigInteger.ZERO)>0)
    {
        if((B.mod(new BigInteger("2")).equals(BigInteger.ONE))==true)
        {
            R=R.multiply(S);
            if(R.compareTo(MOD)>0)
                R=R.mod(MOD);
        }
        S=S.multiply(S);
        if(S.compareTo(MOD)>0)
            S=S.mod(MOD);

        B=B.shiftRight(1);
    }
    return R;
}
public static void main(String[] args) throws java.lang.Exception 
{
    BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
    int T;
    T=Integer.parseInt(br.readLine());
    while(T-->0)
    {
        String str,num = null,num2 = null;
        BigInteger M ;
        BigInteger N ;
        BigInteger MOD=new BigInteger("1000000007");
        str=br.readLine();
        StringTokenizer st=new StringTokenizer(str);
        while(st.hasMoreElements())
        {
            num =(String) st.nextElement();
            num2=(String) st.nextElement();
        }
        N=new BigInteger(num);
        M=new BigInteger(num2);
        BigInteger res=BP(N.mod(MOD),M.mod(MOD),MOD);
        System.out.println(res);
    }
    // TODO code application logic here
}

}


Viewing all articles
Browse latest Browse all 40121

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>