青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品

Brian Warehouse

Some birds aren`t meant to be caged, their feathers are just too bright... ...
posts - 40, comments - 16, trackbacks - 0, articles - 1

SGU 112 a^b-b^a (Java Edition)

Posted on 2010-08-17 13:21 Brian 閱讀(591) 評(píng)論(0)  編輯 收藏 引用 所屬分類(lèi): SGU

You are given natural numbers a and b. Find ab-ba.

Input

Input contains numbers a and b (1≤a,b≤100).

Output

Write answer to output.

Sample Input

2 3

Sample Output

-1

一看到這種題目,就想到高精度算法,Java的大數(shù)。
此舉確實(shí)流氓了一點(diǎn),不過(guò)確實(shí)過(guò)了,鄙人的第一題SGU啊,不許打擊。
過(guò)段時(shí)間看看能不能寫(xiě)出 (C++ Edition) ,啥也別說(shuō)了,上代碼。

SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouseimport java.math.*;
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
import java.util.*;
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
public class Solution
SGU 112 a^b-b^a (Java Edition) - Icho - Brian WarehouseSGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse{
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse   
public static void main(String[] args)
SGU 112 a^b-b^a (Java Edition) - Icho - Brian WarehouseSGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse   
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse{
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      Scanner in 
= new Scanner(System.in);
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      
int a = in.nextInt();
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      
int b = in.nextInt();
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      BigInteger A
=BigInteger.valueOf(a);
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      BigInteger B
=BigInteger.valueOf(b); // A^B
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
      BigInteger rA=BigInteger.valueOf(a);
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      BigInteger rB
=BigInteger.valueOf(b); // store the result after computing
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
      
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      
for(int i=1; i<b; i++// just b-1 times
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
          rA=rA.multiply(A);
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      
for(int i=1; i<a; i++)    
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse          rB
=rB.multiply(B);
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse      System.out.println(rA.subtract(rB)); 
// sub
SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse
   }

SGU 112 a^b-b^a (Java Edition) - Icho - Brian Warehouse}

附《Core Java I》里關(guān)于 大數(shù)的簡(jiǎn)單介紹,講的算比較清晰的了:
Big Numbers
If the precision of the basic integer and floating-point types is not sufficient, you can
turn to a couple of handy classes in the java.math package: BigInteger and BigDecimal. These
are classes for manipulating numbers with an arbitrarily long sequence of digits. The
BigInteger class implements arbitrary precision integer arithmetic, and BigDecimal does the
same for floating-point numbers.
Use the static valueOf method to turn an ordinary number into a big number:
BigInteger a = BigInteger.valueOf(100);
Unfortunately, you cannot use the familiar mathematical operators such as + and * to
combine big numbers. Instead, you must use methods such as add and multiply in the big
number classes.
BigInteger c = a.add(b); // c = a + b
BigInteger d = c.multiply(b.add(BigInteger.valueOf(2))); // d = c * (b + 2)
C++ NOTE: Unlike C++, Java has no programmable operator overloading. There was no way
for the programmer of the BigInteger class to redefine the + and * operators to give the add and
multiply operations of the BigInteger classes. The language designers did overload the + operator
to denote concatenation of strings. They chose not to overload other operators, and they
did not give Java programmers the opportunity to overload operators in their own classes.
Listing 3–6 shows a modification of the lottery odds program of Listing 3–5, updated to
work with big numbers. For example, if you are invited to participate in a lottery in
which you need to pick 60 numbers out of a possible 490 numbers, then this program
will tell you that your odds are 1 in 7163958434619955574151162225400929334117176
12789263493493351 013459481104668848. Good luck!
The program in Listing 3–5 computed the statement
lotteryOdds = lotteryOdds * (n - i + 1) / i;
When big numbers are used, the equivalent statement becomes
lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n - i + 1)).divide(BigInteger.valueOf(i));
Listing 3–6 BigIntegerTest.java
1. import java.math.*;
2. import java.util.*;
3.
4. /**
5. * This program uses big numbers to compute the odds of winning the grand prize in a lottery.
6. * @version 1.20 2004-02-10
7. * @author Cay Horstmann
8. */
9. public class BigIntegerTest
10. {
11. public static void main(String[] args)
12. {
13. Scanner in = new Scanner(System.in);
14.
15. System.out.print("How many numbers do you need to draw? ");
16. int k = in.nextInt();
17.
18. System.out.print("What is the highest number you can draw? ");
19. int n = in.nextInt();
20.
21. /*
22. * compute binomial coefficient n*(n-1)*(n-2)*...*(n-k+1)/(1*2*3*...*k)
23. */
24.
25. BigInteger lotteryOdds = BigInteger.valueOf(1);
26.
27. for (int i = 1; i <= k; i++)
28. lotteryOdds = lotteryOdds.multiply(BigInteger.valueOf(n - i + 1)).divide(
29. BigInteger.valueOf(i));
30.
31. System.out.println("Your odds are 1 in " + lotteryOdds + ". Good luck!");
32. }
33. }

java.math.BigInteger

? BigInteger add(BigInteger other)
? BigInteger subtract(BigInteger other)
? BigInteger multiply(BigInteger other)
? BigInteger divide(BigInteger other)
? BigInteger mod(BigInteger other)
returns the sum, difference, product, quotient, and remainder of this big integer and
other.
? int compareTo(BigInteger other)
returns 0 if this big integer equals other, a negative result if this big integer is less
than other, and a positive result otherwise.
? static BigInteger valueOf(long x)
returns a big integer whose value equals x.
? BigDecimal add(BigDecimal other)
? BigDecimal subtract(BigDecimal other)
? BigDecimal multiply(BigDecimal other)
? BigDecimal divide(BigDecimal other, RoundingMode mode) 5.0
returns the sum, difference, product, or quotient of this big decimal and other.
To compute the quotient, you must supply a rounding mode. The mode
RoundingMode.HALF_UP is the rounding mode that you learned in school (i.e., round
down digits 0 . . . 4, round up digits 5 . . . 9). It is appropriate for routine
calculations. See the API documentation for other rounding modes.
? int compareTo(BigDecimal other)
returns 0 if this big decimal equals other, a negative result if this big decimal is less
than other, and a positive result otherwise.
? static BigDecimal valueOf(long x)
? static BigDecimal valueOf(long x, int scale)
returns a big decimal whose value equals x or x /10scale.

青青草原综合久久大伊人导航_色综合久久天天综合_日日噜噜夜夜狠狠久久丁香五月_热久久这里只有精品
  • <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>
            亚洲欧美春色| 久久国产欧美| 欧美午夜视频在线观看| 一本色道久久88精品综合| 久久婷婷影院| 在线不卡免费欧美| 欧美成人中文| 欧美日韩国产首页| 亚洲欧美乱综合| 午夜精品理论片| 激情久久中文字幕| 亚洲国产精品一区二区尤物区| 久久久久免费观看| 亚洲精品一区二区在线观看| 亚洲人成网站在线观看播放| 欧美日韩在线观看一区二区| 亚洲欧美在线aaa| 欧美在线观看日本一区| 亚洲电影免费| 亚洲精品中文字幕在线观看| 国产精品美女久久久久久2018 | 欧美一区二区三区男人的天堂 | 久久久在线视频| 日韩亚洲一区二区| 亚洲一区久久久| 亚洲国产精品久久久久婷婷老年| 亚洲精品久久久久久久久久久| 国产精品亚洲成人| 欧美福利视频在线| 国产精品久久久久久久久久久久久| 久久久久成人网| 亚洲图片欧洲图片日韩av| 性欧美1819sex性高清| 亚洲日产国产精品| 亚洲欧美国产77777| 亚洲精品社区| 欧美在线黄色| 亚洲一区二区三区在线播放| 久久影院午夜论| 亚洲欧美一区二区激情| 欧美成人精品三级在线观看| 欧美专区福利在线| 欧美日韩卡一卡二| 欧美激情第六页| 国产午夜精品久久久久久久| 亚洲免费观看视频| 亚洲国产综合91精品麻豆| 午夜国产精品视频| 亚洲一区www| 欧美国产三级| 欧美gay视频| 国产真实乱偷精品视频免| 亚洲午夜激情在线| 99精品国产在热久久| 久久夜色精品一区| 久久久午夜电影| 国产精品一区在线观看| 亚洲激情一区二区| 免费在线观看一区二区| 欧美午夜宅男影院| 亚洲美女黄网| a4yy欧美一区二区三区| 六月天综合网| 欧美成人国产一区二区| 国产婷婷97碰碰久久人人蜜臀| 中日韩午夜理伦电影免费| 一区二区日本视频| 欧美人成在线视频| 亚洲日韩第九十九页| 亚洲日产国产精品| 欧美成人免费va影院高清| 免费不卡在线视频| 亚洲国产成人一区| 久久香蕉国产线看观看网| 狼人社综合社区| 亚洲国产成人精品久久| 另类天堂av| 亚洲欧美文学| 欧美另类视频| 亚洲精品美女久久7777777| 亚洲肉体裸体xxxx137| 久久综合伊人| 亚洲高清久久| 一区二区三区视频在线播放| 欧美三级欧美一级| 午夜在线视频观看日韩17c| 久久久久国色av免费看影院| 国模 一区 二区 三区| 久久亚洲精品网站| 亚洲精品在线视频观看| 亚洲欧美日韩精品久久奇米色影视| 国产精品日韩高清| 久久午夜视频| 日韩午夜精品视频| 久久大逼视频| 亚洲国产日本| 国产精品人人做人人爽人人添| 午夜一区二区三视频在线观看| 免费亚洲网站| 亚洲色图制服丝袜| 国内视频一区| 欧美日韩国产综合一区二区| 午夜老司机精品| 亚洲高清在线播放| 先锋影音国产精品| 亚洲第一区色| 国产精品久久久久三级| 玖玖玖国产精品| 99精品免费网| 欧美**人妖| 亚洲欧美自拍偷拍| 亚洲欧洲精品一区二区| 国产精品久久久久久久午夜 | 久久久天天操| 亚洲视频福利| 精品成人一区二区三区四区| 欧美日韩精品在线视频| 久久久不卡网国产精品一区| 夜夜躁日日躁狠狠久久88av| 久久野战av| 亚洲欧美日韩一区| 久久人人爽人人爽| 一区二区欧美日韩视频| 国产亚洲一区在线| 欧美日韩一区二区免费视频| 欧美中文在线观看国产| 一本色道综合亚洲| 欧美国产一区二区| 久久精品视频在线| 午夜精品久久久久久99热软件| 亚洲欧洲在线一区| 伊人久久久大香线蕉综合直播| 国产精品久久网| 欧美日韩色综合| 裸体素人女欧美日韩| 久久久国产精品亚洲一区| 亚洲免费视频网站| 亚洲午夜一区| 99re6这里只有精品视频在线观看| 欧美国产一区二区三区激情无套| 久久久久网站| 久久伊人免费视频| 久久久久久久精| 久久久久久网址| 久久久久国产一区二区三区| 欧美特黄视频| 欧美亚洲视频在线观看| 亚洲视频一二区| 一区二区成人精品| 99一区二区| 一本色道久久99精品综合| 99综合视频| 亚洲深夜影院| 亚洲欧美久久| 欧美在线地址| 久久伊人一区二区| 欧美成年人网站| 亚洲黄一区二区三区| 噜噜爱69成人精品| 欧美高清在线视频| 亚洲精选91| 一区二区高清| 亚洲综合欧美日韩| 欧美一区二区高清在线观看| 久久av一区二区三区| 久久婷婷影院| 欧美日韩精品在线观看| 国产精品毛片高清在线完整版| 国产日韩一区| 亚洲欧美国产视频| 这里只有精品视频在线| 亚洲尤物在线视频观看| 销魂美女一区二区三区视频在线| 欧美亚洲一区三区| 免费久久久一本精品久久区| 欧美精品久久久久久| 国产精品亚洲不卡a| 精品电影在线观看| 宅男噜噜噜66国产日韩在线观看| 午夜在线观看欧美| 欧美韩日亚洲| 亚洲男同1069视频| 免费影视亚洲| 国产精品伊人日日| 亚洲欧洲午夜| 久久精品视频免费观看| 亚洲激情国产| 欧美亚洲免费电影| 欧美精品久久99久久在免费线| 国产日韩在线看片| 一区二区三区欧美在线| 久久久久久国产精品一区| 99re热这里只有精品免费视频| 久久精品一区二区三区中文字幕| 欧美日韩另类视频| 亚洲人成人77777线观看| 欧美一区二区黄色| 欧美肥婆bbw| 亚洲砖区区免费| 女仆av观看一区|