数学题(2)——求数学期望

F.Kevin and Expected Value
Time Limit: 1000 MSMemory Limit: 65536 K
Total Submit: 70 (26 users)Total Accepted: 25 (24 users)Special Judge: No
Description

Kevinsogo is a professor of mathematics, One day he gave an assignment to his students which was hard for them. The students want you to help them in solving the problem.

Given the value of N, 

X = rand( ) mod N

 

Note that rand() returns an integer between 0 and 10^100 (inclusive) uniformly at random.

Find out the expected value of Y.

Input

The first line contains an integer T i.e. the number of test cases.

The next T lines will each contain an integer N.

1T10000

1N5×10^6

Output

Print the output corresponding to each test case in a separate line. Remain exactly 3 number after decimal point.

Sample Input

3

1

5

10

Sample Output

0.000

1.696

2.438


这题目Y是个极限。。。。刚拿到手不知道怎么求。。但因为x是随机的,x范围是0----n-1并且出现的概率都是1/n,所以用数学期望求。。。。第一次做这种题目。。。。QAQ。。。。。

很陌生的一道题目。。。。记下来

#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;


int main()
{
    int n,t
    cin>>t;
    while(t--)
    {
        double sum = 0;
        for(int i =0; i <n; i++)
        {
            double ans = 0;
            for(int j = 0; j<7; j++)//jc如果超过8的话超时。。。。
            {
                ans = sqrt(ans+i*1.0);

            }
            sum += ans;
        }
        printf("%.3lf\n",sum/n);
    }
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值