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

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>
            亚洲国产精品成人| 国产精品一区二区三区乱码| 欧美亚洲一级片| 欧美精品久久99| 免费亚洲一区二区| 国产三区二区一区久久| 亚洲美女在线看| 亚洲免费观看| 快she精品国产999| 毛片一区二区三区| 国产在线精品一区二区夜色| 一区二区三区成人精品| 一本一本久久a久久精品综合麻豆| 久久精品一区二区三区中文字幕| 欧美伊人久久| 国产精品一卡二卡| 亚洲午夜小视频| 亚洲欧美成人网| 国产精品久久久久久久久免费樱桃 | 亚洲欧美日韩精品久久久久| 日韩一级精品| 欧美福利电影网| 亚洲国产精品va| 亚洲日本在线视频观看| 久久久久成人精品| 久久综合亚洲社区| 在线看欧美日韩| 美女视频黄免费的久久| 亚洲第一二三四五区| 亚洲激情视频网站| 欧美黄色aaaa| 夜夜嗨av色综合久久久综合网| 一区二区三区成人| 欧美午夜精品久久久久久浪潮| 日韩午夜在线| 欧美一区二区三区四区视频| 国产精品欧美激情| 午夜免费在线观看精品视频| 久久精品在线播放| 尤物精品在线| 欧美日韩高清免费| 亚洲综合视频一区| 久久久久久久97| 亚洲国产精品久久91精品| 欧美成人r级一区二区三区| 最近中文字幕日韩精品| 亚洲一区二区三区在线| 国产三级精品三级| 免费在线国产精品| 夜夜嗨av一区二区三区四季av | 亚洲看片一区| 午夜国产精品视频| 激情视频一区| 欧美日韩国产在线看| 亚洲欧美日韩成人| 欧美国产日韩一区二区| 亚洲一区二区三| 韩国精品一区二区三区| 欧美久久久久免费| 性伦欧美刺激片在线观看| 免费日韩视频| 亚洲欧美在线另类| 亚洲高清免费视频| 国产精品夜色7777狼人| 久热精品视频在线观看一区| 一区二区成人精品| 欧美14一18处毛片| 性做久久久久久久久| 亚洲欧洲日本国产| 国产日韩精品电影| 欧美另类99xxxxx| 久久精品国产一区二区电影| 亚洲麻豆视频| 免费久久精品视频| 欧美一区二区三区婷婷月色 | 久久久欧美精品| 亚洲黄色一区二区三区| 国产精品美女久久福利网站| 美女主播视频一区| 欧美一区二区三区免费视| 亚洲精品一区二区三| 久久婷婷久久| 欧美怡红院视频| 亚洲午夜免费视频| 日韩一级精品视频在线观看| 韩日成人在线| 国产三级欧美三级| 国产精品久久久91| 欧美日韩精品国产| 欧美精品1区| 欧美 日韩 国产一区二区在线视频 | 亚洲国产一区二区三区在线播 | 国产欧美日韩亚洲精品| 欧美日韩一区二区国产| 欧美成人在线网站| 久久资源av| 久久久之久亚州精品露出| 性欧美精品高清| 午夜精品在线观看| 亚洲一区二区在线免费观看视频| 亚洲另类视频| 亚洲精品社区| 亚洲美女淫视频| 亚洲美女精品成人在线视频| 亚洲二区精品| 亚洲国产婷婷香蕉久久久久久99| 欧美sm重口味系列视频在线观看| 久久嫩草精品久久久久| 久久夜色精品国产欧美乱| 欧美一区三区三区高中清蜜桃 | 最新国产成人在线观看| 亚洲第一黄色| 91久久综合亚洲鲁鲁五月天| 亚洲国产精品一区在线观看不卡| 欧美国产视频一区二区| 亚洲国产91精品在线观看| 亚洲片在线资源| av不卡免费看| 西瓜成人精品人成网站| 欧美与黑人午夜性猛交久久久| 欧美在线观看一区| 久久亚洲视频| 欧美激情亚洲激情| 国产精品二区影院| 国产日韩精品视频一区| 国产一区自拍视频| 亚洲黄色免费电影| 一区二区三区高清在线| 亚洲欧美国产另类| 久久手机免费观看| 亚洲国产成人午夜在线一区| 9久草视频在线视频精品| 亚洲欧美不卡| 蜜臀va亚洲va欧美va天堂| 欧美日本免费一区二区三区| 国产精品久久久久久久9999| 国外成人在线视频网站| 日韩视频精品在线| 翔田千里一区二区| 牛牛国产精品| 亚洲午夜精品在线| 巨胸喷奶水www久久久免费动漫| 欧美久久婷婷综合色| 国产精品入口麻豆原神| 亚洲高清视频中文字幕| 亚洲综合色在线| 开心色5月久久精品| 亚洲精品在线看| 久久久蜜桃精品| 国产精品久久久久77777| 在线免费一区三区| 欧美一级成年大片在线观看| 欧美顶级少妇做爰| 午夜影视日本亚洲欧洲精品| 欧美电影免费观看大全| 国产日韩久久| 中国亚洲黄色| 欧美国产在线观看| 欧美在线二区| 国产精品久久久亚洲一区| 亚洲第一毛片| 欧美中文字幕在线视频| 99国产精品国产精品久久| 久久精品国产第一区二区三区最新章节| 欧美屁股在线| 亚洲人午夜精品免费| 久久精选视频| 亚洲欧美日韩系列| 欧美视频在线不卡| 日韩视频永久免费观看| 久热re这里精品视频在线6| 亚洲一区国产| 欧美偷拍一区二区| 夜夜精品视频| 亚洲欧洲在线观看| 麻豆亚洲精品| 在线观看一区| 欧美成人精品| 久久久人成影片一区二区三区| 国产欧美日韩视频一区二区三区| 亚洲一区二区免费看| 亚洲精选在线观看| 欧美精品在线网站| 日韩一区二区免费高清| 亚洲国产精品成人va在线观看| 久久久久99精品国产片| 国产字幕视频一区二区| 久久国产主播| 欧美中文在线免费| 国内精品久久久久影院 日本资源| 香蕉久久夜色| 午夜日韩视频| 狠狠色丁香婷综合久久| 久久久精品日韩欧美| 欧美一区二区三区婷婷月色| 国产一区二区无遮挡| 久久全球大尺度高清视频| 久久精品72免费观看| 一区二区亚洲精品| 亚洲第一视频网站|