andy6804tw
7/16/2016 - 10:56 AM

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?a=1362 這題利用一個技巧就是先把浮點數轉成字串然後利用substring取得答案,然後題目給的測資有誤答案應該是1810

http://e-tutor.itsa.org.tw/e-Tutor/mod/programming/view.php?a=1362 這題利用一個技巧就是先把浮點數轉成字串然後利用substring取得答案,然後題目給的測資有誤答案應該是1810

import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner scn = new Scanner(System.in);
		int x = scn.nextInt(), n = scn.nextInt();
		double tot = 0.0;
		for (int i = 0; i < x; i++) {
			double t = 1;
			for (int j = i + 1; j >= 1; j--)
				t *= j;
			tot += 1.0 / t;
		}
		System.out.println((Double.toString(tot)).substring((n + 1), n + 5));

	}
	/* 
    題目:[C_MM109-易] 計算密碼
    作者:1010
    時間:西元 2016 年 7 月 */
}