Codeforces 453 A. Little Pony and Expected Maximum, codeforcespony

Source: Internet
Author: User

Codeforces 453 A. Little Pony and Expected Maximum, codeforcespony


(K/n) ^ m-(k-1)/n) ^ m

The probability of repeatedly throwing m requests <= k-the probability of repeatedly throwing m requests <k is still very fast.

A. Little Pony and Expected Maximumtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard 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 hasMFaces: the first face of the dice contains a dot, the second one contains two dots, and so on,M-Th face containsMDots. 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 cocould get after tossing the diceNTimes.

Input

A single line contains two integersMAndN(1 digit ≤ DigitM, Bytes,NLimit ≤ limit 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 too many-since 4.

Sample test (s) 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:

  1. You can get 1 in the first toss, and 2 in the second. Maximum equals to 2.
  2. You can get 1 in the first toss, and 1 in the second. Maximum equals to 1.
  3. You can get 2 in the first toss, and 1 in the second. Maximum equals to 2.
  4. 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:

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



#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cmath>using namespace std;double n,m;int main(){scanf("%lf%lf",&n,&m);double sum=0.;for(int i=1;i<=n;i++){double part=pow(i/n,m)-pow((i-1)/n,m);sum+=part*(double)(i);}printf("%.8lf\n",sum);return 0;}







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.