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

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 閱讀(590) 評論(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),不過確實(shí)過了,鄙人的第一題SGU啊,不許打擊。
過段時(shí)間看看能不能寫出 (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》里關(guān)于 大數(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>
            欧美一区二区成人| 亚洲经典在线| 久久精品日韩欧美| 午夜精品久久| 午夜精品久久久久久久99黑人| 99re66热这里只有精品3直播| 亚洲国产一区二区精品专区| 欧美成年人在线观看| 久久综合九色| 亚洲黄色小视频| 亚洲少妇自拍| 欧美一级黄色录像| 久久久美女艺术照精彩视频福利播放| 欧美一区二区在线免费播放| 久久久久青草大香线综合精品| 免费不卡亚洲欧美| 亚洲精品激情| 欧美亚洲在线视频| 欧美国产专区| 国产欧美在线观看| 亚洲黄色影院| 午夜精品免费在线| 国产日韩精品入口| 亚洲国产精品久久久久秋霞蜜臀| 一本久久综合亚洲鲁鲁五月天| 亚洲欧美综合另类中字| 女生裸体视频一区二区三区| 一本一本久久a久久精品综合妖精 一本一本久久a久久精品综合麻豆 | 韩国av一区二区三区四区| 亚洲高清色综合| 亚洲欧美成人在线| 欧美电影在线| 性欧美长视频| 欧美午夜在线| 亚洲茄子视频| 久久久女女女女999久久| 亚洲精品色图| 久久久美女艺术照精彩视频福利播放| 欧美日韩一区二区高清| 亚洲第一免费播放区| 欧美一区二视频| 日韩午夜电影在线观看| 免费人成网站在线观看欧美高清 | 亚洲乱码国产乱码精品精可以看| 亚洲一线二线三线久久久| 久久亚洲影音av资源网| 香蕉久久久久久久av网站 | 国产日韩精品一区| 亚洲一区国产精品| 亚洲精品久久久蜜桃| 你懂的视频欧美| 亚洲大胆视频| 久久男女视频| 欧美一区二区在线视频| 国产精品永久免费观看| 亚洲在线观看免费| 日韩一级在线观看| 欧美日韩午夜视频在线观看| 亚洲精品欧美一区二区三区| 欧美国产成人精品| 欧美va天堂在线| 国产精品人人爽人人做我的可爱| 亚洲人成久久| 欧美激情中文字幕一区二区| 亚洲国语精品自产拍在线观看| 久久乐国产精品| 久久国产黑丝| 亚洲大胆女人| 亚洲风情在线资源站| 免费在线观看成人av| 欧美国产一区在线| 一区二区三区欧美激情| 99热免费精品| 国产伦精品一区二区三区免费 | 亚洲黄色一区| 亚洲第一中文字幕在线观看| 嫩草国产精品入口| 9l国产精品久久久久麻豆| 亚洲精品日韩在线| 国产精品乱码一区二三区小蝌蚪| 亚洲欧美成aⅴ人在线观看| av72成人在线| 国产视频久久网| 欧美福利影院| 欧美婷婷六月丁香综合色| 午夜视频在线观看一区二区三区| 欧美一区三区三区高中清蜜桃| 亚洲高清中文字幕| 日韩视频精品| 国内一区二区三区在线视频| 亚洲国产日韩综合一区| 国产精品女主播| 美腿丝袜亚洲色图| 欧美三级电影网| 久久香蕉国产线看观看av| 欧美精品91| 久久乐国产精品| 欧美四级在线观看| 鲁大师影院一区二区三区| 欧美精品久久久久久久免费观看| 亚洲欧美日韩国产| 久久嫩草精品久久久久| 亚洲午夜精品久久久久久浪潮| 久久不射中文字幕| 亚洲综合999| 欧美高清视频一区| 久久女同互慰一区二区三区| 欧美日韩一区在线观看| 欧美大片一区二区| 国产一区二区中文| 日韩一本二本av| 在线观看久久av| 亚洲欧美日韩精品久久亚洲区| 久久久久久久999精品视频| 中文日韩电影网站| 久久综合九色| 久久女同精品一区二区| 国产精品久久久久aaaa| 欧美大片专区| 国产日韩欧美日韩| 亚洲激情专区| 欧美成人午夜剧场免费观看| 欧美精品1区| 蜜桃久久av| 国产日韩欧美视频| 一本色道久久综合亚洲精品不| 在线观看一区欧美| 欧美亚洲日本一区| 亚洲综合色丁香婷婷六月图片| 美女999久久久精品视频| 久久综合久久综合久久| 国产欧美一二三区| 亚洲影院污污.| 亚洲欧美日韩专区| 欧美性理论片在线观看片免费| 91久久久久久| 99精品99| 欧美日韩国产免费观看| 91久久国产综合久久| 亚洲日本在线观看| 蜜臀a∨国产成人精品| 欧美不卡高清| 亚洲欧洲精品一区二区三区| 麻豆成人精品| 亚洲电影欧美电影有声小说| 狠狠色伊人亚洲综合网站色| 久久精品国产99精品国产亚洲性色 | 在线国产日韩| 久久久噜噜噜久久久| 欧美77777| 日韩视频专区| 欧美日韩一区国产| 亚洲一区欧美二区| 久久久久久久欧美精品| 一区二区视频免费在线观看| 久久躁狠狠躁夜夜爽| 亚洲国产高清在线| 亚洲视频一区在线| 国产欧美日韩免费看aⅴ视频| 性欧美xxxx视频在线观看| 久久综合伊人77777麻豆| 亚洲高清视频在线| 欧美日韩一区二区三区| 欧美一二三区在线观看| 欧美大片在线观看| 亚洲淫性视频| 黑人巨大精品欧美一区二区小视频| 久久亚洲春色中文字幕久久久| 亚洲电影av| 午夜一区不卡| 亚洲黄色影片| 国产乱码精品一区二区三区忘忧草 | 欧美视频在线一区二区三区| 香蕉久久夜色| 亚洲精品极品| 久久亚洲电影| 亚洲少妇最新在线视频| 亚洲欧洲另类国产综合| 欧美一区二区三区免费视频| 国产伦精品一区二区三区高清版| 午夜精品视频| 亚洲激情视频网| 亚洲欧美日本在线| 亚洲福利视频专区| 国产精品久久久久久久久久尿 | 欧美亚洲综合久久| 亚洲精品在线视频观看| 久久深夜福利| 午夜久久久久久| 99国产精品99久久久久久| 国产一区二区三区精品久久久| 欧美精品在线一区二区| 久久久高清一区二区三区| 亚洲先锋成人| 亚洲免费播放| 欧美激情精品久久久久久蜜臀| 久久国产免费看| 亚洲综合三区| 亚洲午夜精品视频| 一区二区三区不卡视频在线观看 |