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

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>
            欧美亚洲专区| 亚洲人成高清| 性欧美暴力猛交另类hd| 国产精品爽黄69| 午夜日韩福利| 欧美在线播放一区二区| 在线观看免费视频综合| 欧美激情精品久久久久久大尺度| 久久裸体视频| 一区二区三区欧美| 亚洲深夜福利网站| 国产亚洲精品久久久久久| 牛夜精品久久久久久久99黑人| 久久久一本精品99久久精品66| 亚洲黄一区二区| 一本色道久久综合亚洲精品小说| 国产精品爽爽ⅴa在线观看| 久久激情综合网| 欧美成人免费网| 亚洲系列中文字幕| 久久国产精品一区二区三区四区| 亚洲国产一区二区在线| 在线亚洲伦理| 亚洲国产欧洲综合997久久| aⅴ色国产欧美| 国语自产在线不卡| 亚洲人体影院| 激情久久婷婷| 在线视频日韩| 亚洲狼人精品一区二区三区| 亚洲欧美日韩精品久久久久| 亚洲九九九在线观看| 欧美一区二区三区免费视| 91久久一区二区| 欧美在线视频不卡| 亚洲一级在线| 欧美精品v国产精品v日韩精品| 久久福利一区| 国产精品久久久久久久久果冻传媒 | 日韩视频在线免费观看| 国产一区二区三区无遮挡| 亚洲乱码国产乱码精品精| 亚洲电影下载| 久久福利影视| 欧美亚洲综合网| 欧美日韩在线免费视频| 欧美α欧美αv大片| 国产日韩欧美在线| 一区二区三区精密机械公司| 亚洲精品一区中文| 久久亚洲一区二区| 久久躁狠狠躁夜夜爽| 国产一区 二区 三区一级| 亚洲深夜福利视频| 亚洲一区二区在| 欧美日韩精品免费观看视频| 欧美韩国日本一区| 亚洲第一成人在线| 久久夜色精品国产噜噜av| 久久综合亚州| 精品成人在线观看| 久久久久久噜噜噜久久久精品| 羞羞视频在线观看欧美| 国产精品久久久久久av福利软件| 日韩一级黄色片| 亚洲天堂免费观看| 国产精品福利片| 亚洲女ⅴideoshd黑人| 亚洲欧美在线观看| 国产视频一区在线观看| 欧美一区二区女人| 老司机免费视频久久| 亚洲国产精品热久久| 免费在线欧美黄色| 日韩午夜在线播放| 亚洲一区自拍| 国产美女精品免费电影| 久久激情五月激情| 美女在线一区二区| 亚洲美女色禁图| 欧美亚日韩国产aⅴ精品中极品| 亚洲深夜影院| 久久久久中文| 亚洲日本免费| 欧美视频在线播放| 欧美一区二区三区婷婷月色| 麻豆成人综合网| 99视频在线观看一区三区| 国产精品日韩在线一区| 久久精品视频网| 亚洲精品乱码久久久久久| 午夜精品久久久久久99热| 国产亚洲人成a一在线v站 | 亚洲美女中出| 欧美尤物一区| 最新成人av在线| 国产精品久久久久久久久久免费看 | 久久激情久久| 亚洲免费观看| 国产日韩欧美二区| 欧美成人国产一区二区| 亚洲制服欧美中文字幕中文字幕| 鲁大师成人一区二区三区| 亚洲视频免费在线观看| 狠狠爱www人成狠狠爱综合网| 欧美精品一区二区三区蜜臀| 午夜精品久久久久| 亚洲日本激情| 蜜桃久久精品一区二区| 亚洲免费视频一区二区| 91久久国产综合久久91精品网站| 国产精品激情av在线播放| 蜜桃久久av| 欧美在线亚洲一区| 亚洲一区二区三区久久| 亚洲日本激情| 欧美激情亚洲另类| 久久先锋资源| 久久精品国产综合精品| 亚洲免费视频一区二区| 亚洲免费观看高清在线观看 | 亚洲福利国产精品| 久久人人97超碰精品888| 亚洲在线1234| 一区二区三区视频在线观看| 在线观看欧美一区| 国内一区二区在线视频观看| 国产精品国产三级国产专播品爱网 | 久久爱www.| 亚洲欧美一区二区在线观看| 亚洲精品乱码久久久久| 怡红院av一区二区三区| 国产欧美日韩在线播放| 国产精品白丝av嫩草影院| 欧美日韩久久久久久| 欧美另类在线观看| 欧美精品亚洲二区| 欧美激情a∨在线视频播放| 蜜臀av性久久久久蜜臀aⅴ| 久久亚洲美女| 免费观看成人www动漫视频| 久久综合影视| 欧美成年人网站| 欧美夫妇交换俱乐部在线观看| 久久综合伊人77777麻豆| 欧美aaa级| 欧美精品乱人伦久久久久久| 欧美日韩国产系列| 欧美午夜精品一区| 国产精品一区二区在线观看网站| 国产精品日韩在线一区| 国产日韩一区| 在线成人中文字幕| 亚洲精品在线免费| 一本大道久久精品懂色aⅴ| 国产精品99久久久久久人| 亚洲尤物视频在线| 欧美一区精品| 免费欧美在线视频| 亚洲电影免费在线| 夜夜嗨av色综合久久久综合网| 中文日韩在线视频| 久久国产精品电影| 欧美交受高潮1| 国产精品欧美日韩一区二区| 韩国三级在线一区| 99热精品在线| 久久成人精品无人区| 欧美xxx在线观看| 在线视频精品一| 久久久噜噜噜久噜久久| 欧美日本在线一区| 国产亚洲综合在线| 亚洲人成在线播放| 欧美在线播放高清精品| 欧美va天堂在线| 亚洲天堂av在线免费| 久久人人爽爽爽人久久久| 欧美日韩国产限制| 玉米视频成人免费看| 亚洲调教视频在线观看| 久久先锋影音| 亚洲五月婷婷| 欧美黄色日本| 国产综合欧美在线看| 一区二区三区日韩精品视频| 久久综合国产精品| 中文在线一区| 欧美激情视频一区二区三区免费| 国产美女一区二区| 国产精品99久久久久久久久久久久 | 国产一区二区三区在线观看免费视频| 亚洲欧洲精品一区二区三区不卡 | 国产欧美一区二区精品性色| 99re6这里只有精品视频在线观看| 久久久久成人网| 亚洲视频久久| 欧美日产在线观看| 亚洲激情第一页| 久久―日本道色综合久久|