You are not logged in. Please login at www.codechef.com to post your questions!

×

Google Code jam kickStart Problem A : Huge Number

Problem Link

Can any one please tell it is giving wrong answer but it is working for sample test case My Solution

/*
###### ##### ###### ######

# # # # # # # # # # # # # # # # # ## # # ## # # # # # # # # # # # # #

# # # # # # # # #

/ import java.util.; import java.lang.; import java.io.; import java.math.*; class hugenumber { public static void main(String args[] ) throws Exception { Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in))); PrintStream p = System.out; int t =scan.nextInt(); int i=1; while(t-->0){

        int a =scan.nextInt();
        int n =scan.nextInt();
        int d =scan.nextInt();
        BigInteger fact = factorial(n);
        BigInteger bi1 = new BigInteger(Integer.toString(a));
        BigInteger bi2 = new BigInteger(Integer.toString(d));
        BigInteger bi3 = bi1.modPow(fact, bi2);
        p.println("Case #" + i + ": " +bi3);
        i++;
    }

}
static BigInteger factorial(int n){
    BigInteger fact= BigInteger.ONE;
    int factorialNo = 100;

    for (int i = 2; i <= factorialNo; i++){
        fact = fact.multiply(new BigInteger(String.valueOf(i)));
    }
    return fact;
}

}

asked 22 Oct '17, 13:32

drjaat's gravatar image

2★drjaat
267111
accept rate: 6%

y were u looping till 100 in factorial method?

(22 Oct '17, 14:11) beginner_11114★

that was silly how did i miss that Thanks @beginner_1111

(22 Oct '17, 14:44) drjaat2★
toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:

×633
×40
×40

question asked: 22 Oct '17, 13:32

question was seen: 559 times

last updated: 22 Oct '17, 14:44