Hdu 2035 people See people love A^b (Java)

Source: Internet
Author: User
Tags greatest common divisor scanner class in java

Problem:
The problem needs to be stored in large numbers, but int can also hold the input n,m so it is not necessary to use BigInteger to install.
When starting to load N with BigInteger, even converting 0 to BigInteger, the IF statement used to judge 0 has no effect, the reason is unknown.




Some functions for handling large numbers:
Ⅰ Basic functions:
1.valueOf (parament); To convert a parameter to a developed type
such as int a=3;
BigInteger b=biginteger.valueof (a);
Then b=3;
String s= "12345";
BigInteger c=biginteger.valueof (s);
Then c=12345;


2.add (); Add large integers
BigInteger a=new BigInteger ("23");
BigInteger b=new BigInteger ("34");
A. Add (b);


3.subtract (); Subtraction
4.multiply (); Multiply
5.divide (); Divide rounding
6.remainder (); Take surplus
7.pow (); A.pow (b) =a^b
8.GCD (); Greatest common divisor
9.abs (); Absolute
10.negate (); Take the inverse number
11.mod (); A.mod (b) =a%b=a.remainder (b);
12.max (); Min ();
13.punlic int Comareto ();
14.boolean equals (); is equal
15.BigInteger Constructors:
Generally used in the following two kinds:
BigInteger (String val);
Converts the specified string to a decimal representation;
BigInteger (String val,int radix);
Converts the string representation of a BigInteger of a specified cardinality to BigInteger
Ⅱ. Basic constants:
A=biginteger.one 1
B=biginteger.ten 10
C=biginteger.zero 0
Ⅲ. Basic operations
1. Read in:
Use the Scanner class definition object for console reading, scanner class in java.util.* package
Scanner cin=new Scanner (system.in);//Read in
while (Cin.hasnext ())//equals to!=eof
{
int n;
BigInteger m;
N=cin.nextint (); Read into an int;
M=cin. BigInteger ();//read into a BigInteger;
System.out.print (M.tostring ());
}



People See people love a^bTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 27559 Accepted Submission (s): 18833


Problem description An integer representing the last three digits of the a^b.
Description: The meaning of A^b is "A's B-square"

Input data contains multiple test instances, one row per instance, consisting of two positive integers a and B (1<=a,b<=10000), and if a=0, b=0, indicates the end of the input data and does not process.
Output for each test instance, print the last three bits of the a^b that represent the integers, one row for each output.

Sample Input
2 312 66789) 100000 0

Sample Output
89841

Code:

Import Java.math.biginteger;import java.util.*;p ublic class main{public static void Main (String args[]) {Scanner cin=new Scanner (system.in), while (Cin.hasnext ()) {int n=cin.nextint (), int m=cin.nextint (), if (n==0&&m==0) {break;} Else{biginteger s; BigInteger k= biginteger.valueof (n); s= K.pow (M); BigInteger l=new BigInteger ("1000"); System.out.println (S.mod (L));}}}


Hdu 2035 people See people love A^b (Java)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.