Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
Re:大家可以用概率的阶乘公式来过,不过要用double,不然wa,符Ac java代码,注,double表示的数比long的大In Reply To:Re:大家可以用概率的阶乘公式来过,不过要用double,不然wa,符Ac java代码,注,double表示的数比long的大 Posted by:Jack_whj at 2013-12-03 17:27:24 import java.util.Scanner; import java.io.BufferedInputStream; public class Main { public static void main(String[] args) { Scanner in = new Scanner(new BufferedInputStream(System.in)); long n = in.nextLong(), k = in.nextLong(); while(n > 0){ long kCn = 1; k = (k > n-k ? n-k : k); for(long i = n, j = 1; j <= k; i--, j++) kCn = kCn * i / j; System.out.println(kCn); n = in.nextLong(); k = in.nextLong(); } in.close(); } } Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator