编程介的小学生 2017-02-06 13:58 采纳率: 20.5%
浏览 853
已采纳

Expectation

问题描述 :

Eric has constructed an easy scheme for generating random integer numbers. His scheme inputs an integer n and generates evenly distributed random integer value between 0 and (n − 1) inclusive. For example, if n = 3, the scheme generates 0, 1 or 2, each with probability 1/3.

Now Eric is planning to construct more complicated schemes. The first one will consist of two independent random generators with their outputs forwarded to his favorite XOR gate, which does bitwise exclusive or with its two inputs.

Eric’s friend Nick studies math. Nick said that the scheme is very interesting, and the most interesting thing is the expectation of the result. Now they both think how to calculate the expectation. Could you help them?

Remember that the expectation of the random variable is its average value. For a variable ξ with nonnegative integer values it can be calculated as

,

where pi is the probability of ξ being equal to i.

输入:

The first line of the input contains the number k of cases to solve (1 ≤ k ≤ 1 000). Each case consists of a single integer 1 ≤ n ≤ 109 on a separate line.

输出:

For each case output the expected value of the new Eric’s scheme with at least two digits after the decimal point. Output each result on a separate line.

样例输入:

2
3
4
样例输出:

1.33
1.50

  • 写回答

1条回答 默认 最新

  • threenewbee 2017-02-12 15:42
    关注
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Windows server update services
  • ¥15 关于#c语言#的问题:我现在在做一个墨水屏设计,2.9英寸的小屏怎么换4.2英寸大屏
  • ¥15 模糊pid与pid仿真结果几乎一样
  • ¥15 java的GUI的运用
  • ¥15 Web.config连不上数据库
  • ¥15 我想付费需要AKM公司DSP开发资料及相关开发。
  • ¥15 怎么配置广告联盟瀑布流
  • ¥15 Rstudio 保存代码闪退
  • ¥20 win系统的PYQT程序生成的数据如何放入云服务器阿里云window版?
  • ¥50 invest生境质量模块