A. Little Pony and Expected Maximum

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutter Shy. But she kept losing. Having returned to the castle, Twilight Sparkle became interested in the dice that were used in the game.

The dice has m faces: the first face of the dice contains a dot, the second one contains two dots, and so on, the m-th face contains m dots. Twilight Sparkle is sure that when the dice is tossed, each face appears with probability . Also she knows that each toss is independent from others. Help her to calculate the expected maximum number of dots she could get after tossing the dice n times.

Input

A single line contains two integers m and n (1 ≤ m, n ≤ 105).

Output

Output a single real number corresponding to the expected maximum. The answer will be considered correct if its relative or absolute error doesn't exceed 10  - 4.

Examples

Input

6 1

Output

3.500000000000

Input

6 3

Output

4.958333333333

Input

2 2

Output

1.750000000000

Note

Consider the third test example. If you've made two tosses:

You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
You can get 2 in the first toss, and 2 in the second. Maximum equals to 2.

The probability of each outcome is 0.25, that is expectation equals to:

You can read about expectation using the following link: http://en.wikipedia.org/wiki/Expected_value

题目大意

给你一个\(m\)个面的骰子,第\(i\)个面上的数为\(i\),投\(n\)次,问这\(n\)次中最大值的期望。

题解

考虑枚举最大值\(i\),直接算不太好算,考虑容斥。

最大值为\(i\)的方案 = 所有数小于等于\(i\)的方案 - 不包含\(i\)的方案,即为所有数小于等于\(i\)且包含\(i\)的方案,即

\[Ans_i = i^n - (i-1)^n
\]

总方案数除以\(m^n\)即可

由于太大可能会溢出,要边计算边除,即

\[\frac{Ans_i}{m^n} = \frac{i^n - (i-1)^n}{m^n} = \frac{i}{m}^n - \frac{i-1}{m}^n
\]

答案即为$$\sum_{i=1}^{m} Ans_i$$

嘴巴题9 Codeforces 453A. Little Pony and Expected Maximum的更多相关文章

  1. CodeForces - 453A Little Pony and Expected Maximum

    http://codeforces.com/problemset/problem/453/A 题目大意: 给定一个m面的筛子,求掷n次后,得到的最大的点数的期望 题解 设f[i]表示掷出 <= ...

  2. CodeForces 454C Little Pony and Expected Maximum

    Little Pony and Expected Maximum Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I6 ...

  3. codeforces C. Little Pony and Expected Maximum

    题意:一个筛子有m个面,然后扔n次,求最大值的期望; 思路:最大值为1 有1种,2有2n-1种,  3有3n -2n 种   所以为m的时有mn -(m-1)n 种,所以分别求每一种的概率,然后乘以这 ...

  4. cf 453A.Little Pony and Expected Maximum

    水了一上午.. 拿6面举例子吧,因为是投掷m次取最大,最大是1概率(1/6)^m;最大是2就可以取到(1,2)那么概率就是(1/3)^m-(1/6)^m.(当前减去上一个) #include<b ...

  5. Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题

    A. Little Pony and Expected Maximum Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.c ...

  6. Codeforces Round #259 (Div. 2) C - Little Pony and Expected Maximum (数学期望)

    题目链接 题意 : 一个m面的骰子,掷n次,问得到最大值的期望. 思路 : 数学期望,离散时的公式是E(X) = X1*p(X1) + X2*p(X2) + …… + Xn*p(Xn) p(xi)的是 ...

  7. 【CF 453A】 A. Little Pony and Expected Maximum(期望、快速幂)

    A. Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megabytes ...

  8. E. Little Pony and Expected Maximum(组合期望)

    题目描述: Little Pony and Expected Maximum time limit per test 1 second memory limit per test 256 megaby ...

  9. CF453A Little Pony and Expected Maximum 期望dp

    LINK:Little Pony and Expected Maximum 容易设出状态f[i][j]表示前i次最大值为j的概率. 转移很显然 不过复杂度很高. 考虑优化.考虑直接求出最大值为j的概率 ...

随机推荐

  1. weblux上传图片

    我是接口接收图片然后上传到阿里云上,由于引入的是spring weblux,所以使用方式不同,代码如下 @PostMapping(value = "/upload", consum ...

  2. NX二次开发-UFUN获取一个图层类别的tag UF_LAYER_ask_category_tag

    NX11+VS2013 #include <uf.h> #include <uf_ui.h> #include <uf_layer.h> UF_initialize ...

  3. NX二次开发-char*转换成CString,多字节转换成Unicode使用方法

    //定义一个结构体记录 struct group { CString text; //定义一个CString std::vector<tag_t> boudaries; std::vect ...

  4. vue wabpack 切换开发环境 和生成环境 的接口地址

    /config/dev.env.js 新增一行 var merge = require('webpack-merge') var prodEnv = require('./prod.env') mod ...

  5. java带jar编译与运行

    javac -classpath ./wxpay-sdk-0.0.3.jar HttpsTest2.java java -cp .:./wxpay-sdk-0.0.3.jar HttpsTest2

  6. ionic-CSS:ionic Toggle(切换开关)

    ylbtech-ionic-CSS:ionic Toggle(切换开关) 1.返回顶部 1. ionic Toggle(切换开关) 切换开关类似与 HTML 的 checkbox 标签,但它更易于在移 ...

  7. Python中and_Or

    自 http://www.cnblogs.com/BeginMan/p/3197123.html 一.and: 在Python 中,and 和 or 执行布尔逻辑演算,如你所期待的一样,但是它们并不返 ...

  8. Lucene TFIDFSimilarity评分公式详解

    版权声明:本文为博主原创文章,遵循CC 4.0 by-sa版权协议,转载请附上原文出处链接和本声明. 本文链接:https://blog.csdn.net/zteny/article/details/ ...

  9. Algo: Basic

    1. 二维数组的查找 2. 替换空格 3. 从尾到头打印链表 4. 重建二叉树 5. 用两个栈实现队列 6. 旋转数组的最小数字 7. 斐波那契数列 8. 跳台阶 9. 变态跳台阶 10. 矩阵覆盖 ...

  10. sql (8) AVG

    SQL avg 语法SELECT AVG(column_name) FROM table_name新建表:StudentS S_id Grade Name phone1 98 小明 1234562 9 ...