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

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)  編輯 收藏 引用 所屬分類: 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í)間看看能不能寫出 (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>
            99国产精品久久久| 在线亚洲欧美视频| 久久免费少妇高潮久久精品99| 国产丝袜一区二区| 欧美尤物巨大精品爽| 午夜精品视频在线观看| 韩国女主播一区二区三区| 久久夜色精品亚洲噜噜国产mv| 久久一区欧美| 夜夜狂射影院欧美极品| 中文成人激情娱乐网| 国产欧美一区二区三区沐欲 | 国产一区二区av| 亚洲伊人久久综合| 亚洲男人的天堂在线| 国产综合久久久久久鬼色| 免费观看成人| 欧美激情1区2区| 午夜精品久久久久久99热| 久久精品九九| 亚洲最新视频在线| 午夜性色一区二区三区免费视频| 伊人色综合久久天天| 日韩视频在线你懂得| 国产亚洲人成网站在线观看| 亚洲国产精品一区二区久| 欧美视频一区二| 麻豆免费精品视频| 欧美性猛交xxxx乱大交蜜桃| 久久资源av| 欧美三级电影一区| 免费人成精品欧美精品| 国产精品性做久久久久久| 久久综合五月天婷婷伊人| 欧美性jizz18性欧美| 欧美v日韩v国产v| 国产欧美精品在线观看| 亚洲精品一区在线| 在线观看欧美成人| 香蕉国产精品偷在线观看不卡| 一本色道久久综合精品竹菊 | 欧美国产日韩在线观看| 国产精品久久影院| 亚洲精选一区二区| 亚洲欧洲日本在线| 久久九九久久九九| 久久大逼视频| 国产精品久久久久永久免费观看| 亚洲欧洲综合| 亚洲国产精品久久久| 欧美在线视频一区二区三区| 午夜在线视频一区二区区别| 欧美人与禽性xxxxx杂性| 欧美激情91| 亚洲国产高潮在线观看| 久久久综合视频| 久久视频在线免费观看| 国产一区深夜福利| 午夜久久久久久久久久一区二区| 亚洲欧美不卡| 国产精品美女www爽爽爽视频| 亚洲精品在线免费| 99精品视频一区二区三区| 欧美高清在线一区| 亚洲国产欧美在线人成| 亚洲区一区二区三区| 欧美国产1区2区| 亚洲国产精品va在看黑人| 亚洲人成网站影音先锋播放| 老牛影视一区二区三区| 免费毛片一区二区三区久久久| 狠狠v欧美v日韩v亚洲ⅴ| 久久精品国产精品亚洲综合| 噜噜噜躁狠狠躁狠狠精品视频| 伊人婷婷欧美激情| 欧美.www| 一区二区激情| 久久精品噜噜噜成人av农村| 国语自产偷拍精品视频偷 | 欧美91大片| 亚洲精品网址在线观看| 欧美日韩免费在线视频| 亚洲一区二区av电影| 久久爱www.| 揄拍成人国产精品视频| 狠狠色伊人亚洲综合网站色| 亚洲精品久久久久久下一站| 99这里只有久久精品视频| 欧美成人国产一区二区| 日韩视频久久| 久久精品官网| 亚洲区在线播放| 欧美午夜精品理论片a级大开眼界 欧美午夜精品理论片a级按摩 | 国内精品久久久久影院色| 久久久99国产精品免费| 91久久精品一区| 亚洲欧美日韩天堂一区二区| 精品成人在线| 欧美精品一区二| 香蕉国产精品偷在线观看不卡| 久久视频精品在线| 99天天综合性| 国产一区美女| 欧美日韩精品欧美日韩精品一| 亚洲女ⅴideoshd黑人| 久久一区免费| 亚洲女同在线| 亚洲国产美国国产综合一区二区| 欧美视频精品在线| 久久午夜羞羞影院免费观看| 制服诱惑一区二区| 欧美国产综合一区二区| 久久精品日产第一区二区三区| 日韩视频在线永久播放| 国产麻豆日韩欧美久久| 欧美破处大片在线视频| 久久久久国产一区二区三区| aa级大片欧美| 亚洲第一色中文字幕| 久久精品二区| 亚洲免费在线视频| avtt综合网| 亚洲精品乱码久久久久久日本蜜臀 | 亚洲人体大胆视频| 韩国精品在线观看| 国产精品一区二区久久久| 欧美精品v日韩精品v国产精品| 久久精品日韩欧美| 亚洲欧美日产图| 中文久久精品| 日韩一级欧洲| 亚洲精品久久久久久久久久久久久| 免费91麻豆精品国产自产在线观看| 欧美在线高清视频| 亚洲欧洲av一区二区三区久久| 99精品福利视频| 亚洲乱码一区二区| 亚洲精品国偷自产在线99热| 在线观看久久av| 在线观看成人一级片| 国产在线精品一区二区夜色| 国产日韩欧美视频| 国产日韩欧美制服另类| 国产精品亚洲а∨天堂免在线| 国产精品国产三级国产aⅴ9色| 欧美日韩午夜剧场| 欧美视频在线免费看| 国产精品久久久对白| 国产精品嫩草影院av蜜臀| 国产精品另类一区| 国产麻豆综合| 韩日视频一区| 亚洲国产日韩欧美在线99| 亚洲韩日在线| 一区二区三区欧美亚洲| 亚洲欧美日韩综合一区| 欧美一区二区视频在线| 久久精品一区四区| 欧美成人精品三级在线观看| 亚洲二区视频在线| 日韩网站在线观看| 亚洲欧美日韩在线高清直播| 久久九九全国免费精品观看| 欧美aⅴ99久久黑人专区| 欧美日韩精品免费观看视频| 国产精品亚洲综合久久| 狠狠久久亚洲欧美| 日韩视频在线免费| 午夜精品福利视频| 久久综合久久久久88| 亚洲高清视频一区| 亚洲一区二区三区乱码aⅴ| 久久gogo国模裸体人体| 欧美高清在线一区二区| 国产精品青草久久| 在线成人国产| 亚洲男人第一av网站| 蜜桃久久精品一区二区| 日韩视频在线一区二区| 久久精品国产免费| 欧美日韩国产首页在线观看| 国产午夜久久久久| 99热在线精品观看| 久久先锋资源| 中国av一区| 欧美成人免费网站| 国产日韩精品久久| 一区二区三区高清视频在线观看| 久久国产主播| 亚洲人成在线播放| 久久久久久亚洲综合影院红桃| 欧美性猛交99久久久久99按摩| 在线播放中文字幕一区| 午夜久久久久久久久久一区二区| 欧美韩日一区二区| 久久xxxx精品视频| 国产精品久久久久久久久婷婷 | 亚洲精品1区| 久久国产欧美精品| 中文日韩在线|