import java.math.BigDecimal; import java.util.Scanner; public class Main { public BigDecimal goldenCoin(double n){ BigDecimal p; if (n >= 990){ p = new BigDecimal("1"); }else { BigDecimal m = new BigDecimal("1"); for (int i = 0; i < n ; i ++){ m = m .multiply (new BigDecimal(Double.toString(990 - i))); m = m.divide(new BigDecimal(Double.toString(1000 - i)), 6, BigDecimal.ROUND_HALF_UP); } p = new BigDecimal(1) .subtract(m) ; } return p; } public static void main(String[] args){ Scanner in = new Scanner(System.in); double n = in.nextDouble(); Main goldenCoin = new Main(); System.out.println(goldenCoin.goldenCoin(n).setScale(6,BigDecimal.ROUND_HALF_UP)); } }
点赞 4

相关推荐

我已成为0offer的糕手:别惯着,胆子都是练出来的,这里认怂了,那以后被裁应届被拖工资还敢抗争?
点赞 评论 收藏
分享
牛客279957775号:铁暗恋
点赞 评论 收藏
分享
牛客网
牛客企业服务