Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:大家可以用概率的阶乘公式来过,不过要用double,不然wa,符Ac java代码,注,double表示的数比long的大

Posted by forif at 2014-03-16 12:01:30 on Problem 2249
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:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator