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

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 閱讀(588) 評論(0)  編輯 收藏 引用 所屬分類: 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ù)。
此舉確實流氓了一點,不過確實過了,鄙人的第一題SGU啊,不許打擊。
過段時間看看能不能寫出 (C++ Edition) ,啥也別說了,上代碼。

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》里關于 大數(shù)的簡單介紹,講的算比較清晰的了:
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>
            欧美伊人久久久久久午夜久久久久 | 在线不卡中文字幕| 国产精品porn| 国产精品久久99| 欧美三级视频在线| 国产精品永久免费| 在线观看欧美| 亚洲精品少妇30p| 中文国产一区| 久久精品导航| 久久综合影音| 亚洲精品在线二区| 亚洲欧美日韩系列| 六十路精品视频| 欧美日韩日本国产亚洲在线| 欧美性大战久久久久久久| 国产欧美一区二区精品性色| 伊大人香蕉综合8在线视| 亚洲美女区一区| 午夜在线精品偷拍| 欧美a级一区| 日韩视频在线观看| 久久久精品免费视频| 欧美日韩亚洲一区二区| 国产一区在线视频| 亚洲高清精品中出| 久久欧美中文字幕| 欧美国产日韩一区二区| 亚洲一区二区三区精品在线| 久久麻豆一区二区| 国产精品一级在线| 日韩午夜免费视频| 美女性感视频久久久| 亚洲深夜福利| 免费观看成人| 国内精品伊人久久久久av一坑| 亚洲天堂免费在线观看视频| 美女尤物久久精品| 亚洲欧美成人在线| 欧美精品三级日韩久久| 黄色小说综合网站| 久久国产一区| 亚洲视频在线观看视频| 欧美人在线视频| 亚洲国产一区在线| 每日更新成人在线视频| 羞羞漫画18久久大片| 欧美日韩另类视频| 亚洲国内精品在线| 欧美成人在线免费视频| 欧美在线在线| 国产日韩欧美在线| 亚洲欧美另类在线观看| 亚洲精品中文字| 欧美黄色免费| 亚洲黄色免费| 亚洲电影第三页| 久久久久综合| 影音先锋成人资源站| 欧美在线日韩精品| 午夜精品久久久久久久 | 国产精品豆花视频| 宅男在线国产精品| 亚洲国产精品视频| 欧美成人69av| 一本色道久久加勒比精品| 亚洲国产精品视频| 欧美高清hd18日本| 99视频有精品| 夜夜嗨av一区二区三区免费区| 欧美精品一区二区三区很污很色的| 91久久黄色| 亚洲欧洲在线免费| 欧美日韩亚洲一区在线观看| 一本久道久久综合婷婷鲸鱼| 亚洲理论电影网| 欧美午夜精品电影| 午夜在线播放视频欧美| 久久国产精品久久久久久| 国产一区亚洲| 女女同性精品视频| 欧美日韩一二区| 欧美影院精品一区| 久久综合九色欧美综合狠狠| 亚洲免费精彩视频| 久久野战av| 亚洲美女黄色| 亚洲专区一区| 在线精品福利| 一区二区三区精品视频在线观看| 国产精品久久久久三级| 久久精品电影| 欧美波霸影院| 久久高清一区| 美女黄毛**国产精品啪啪| 一区二区三区视频在线观看 | 久久成人久久爱| 亚洲精品午夜精品| 亚洲欧美久久久久一区二区三区| 狠狠色丁香婷婷综合影院| 欧美激情在线观看| 欧美视频在线一区| 蜜桃精品一区二区三区| 欧美巨乳在线| 免费在线成人| 国产精品嫩草99a| 欧美国产乱视频| 国产精品久久久| 亚洲第一福利视频| 国内一区二区在线视频观看| 亚洲人成7777| 最新日韩中文字幕| 欧美亚洲视频在线观看| 99re视频这里只有精品| 久久噜噜噜精品国产亚洲综合| 日韩一区二区电影网| 久久久国产午夜精品| 午夜欧美大尺度福利影院在线看| 欧美黄在线观看| 欧美国产精品日韩| 国产亚洲精品aa午夜观看| 一区二区三区精品久久久| 亚洲另类自拍| 蜜臀av一级做a爰片久久| 久久精品国产精品亚洲| 国产精品久久久久免费a∨大胸| 亚洲国产日韩一区二区| 一区二区亚洲| 久久久国产精彩视频美女艺术照福利| 欧美一区二区三区日韩视频| 国产精品乱码久久久久久| 日韩系列在线| 在线视频亚洲欧美| 欧美日韩一区二区欧美激情 | 亚洲福利专区| 久久久久久久一区| 久久资源在线| 亚洲国产色一区| 欧美成人一品| 亚洲日本激情| 亚洲一区二区成人在线观看| 欧美日韩亚洲视频| 亚洲午夜一区| 久久久久国产成人精品亚洲午夜| 国产精品日本一区二区| 亚洲网站视频福利| 欧美专区日韩视频| 狠狠色2019综合网| 午夜精品福利视频| 性一交一乱一区二区洋洋av| 欧美一区二区在线免费观看| 国产精品区一区二区三区| 亚洲在线电影| 久久国产精品久久久久久久久久 | 欧美国产日韩一区二区| 免费成人黄色| 亚洲美女区一区| 欧美日韩18| 亚洲一二区在线| 久久9热精品视频| 国外成人性视频| 久久婷婷色综合| 亚洲精品色婷婷福利天堂| 亚洲永久免费av| 国产亚洲精品久久久久久| 久久久久久一区二区三区| 欧美1区视频| 一区二区三区精品国产| 国产精品乱子久久久久| 欧美一区二区视频观看视频| 久久影院午夜片一区| 一区二区三区欧美在线观看| 国产欧美精品va在线观看| 久久久精品网| av成人免费在线| 久久亚洲综合色| 日韩午夜av| 国产精品一区二区久久久| 久久理论片午夜琪琪电影网| 亚洲精品视频在线观看网站| 欧美在线视频免费| 亚洲精品系列| 国产一区二区三区四区| 欧美日韩国产成人| 久久久久国产精品www| 一区二区三区视频在线| 久久亚洲影音av资源网| 亚洲性线免费观看视频成熟| 精东粉嫩av免费一区二区三区| 欧美久久电影| 欧美在线观看一二区| 在线视频一区二区| 亚洲电影av| 久久人人97超碰精品888| 在线亚洲免费视频| 最新国产乱人伦偷精品免费网站| 国产欧美韩日| 欧美日韩午夜精品| 欧美阿v一级看视频| 先锋影音国产一区|