Zeyad and Ehab are playing a simple card game, each player initially has a deck of n cards numbered from 1 to n, the game lasts n turns and in each turn both players privately choose one card and then both players reveal the chosen cards, the player that chose the card with the higher number earns points equal to that number, for example if Ehab chooses 4 and Zeyad chooses 6 Zeyad earns 6 points, if the numbers chosen are equal no one earns any point, the cards chosen do not return to the deck, they are discarded instead.
Ehab doesn’t care about winning or losing, he cares about mathematical values of the game, specifically he wants to know the expected number of points he’ll earn considering all possible outcomes, can you help him?
Input
The first and only line of input contains a single integer n(1≤n≤106).
Output
Print a real number, the expected number of points Ehab will earn in the game.
The answer is considered correct if the absolute or relative error is not greater than 10−6.
Examples
Input
3
Output
2.6666666667
Input
7
Output
16.0000000000
题解:首先可以退一下概率公式,假设共7张牌,第一张出手,概率为1/7,其余几张留下的概率为6/7,出手的概率均为1/6,所以第二张出手的概率为6/7 * 1/6 = 1/7,其余的同理,可以发现,不管前方有多少张牌,每张牌的概率就是1/n,所以根据期望=sum(np)得,也就很简单了,下面是AC代码:
#include<cstdio>
#include<cstring>
int main(){
int n,i;
scanf("%d",&n);
double ans=0;
for(i=1;i<=n;i++)
ans+=(double)(i-1)*1.0*i/n*1.0;//出i时只有对手出1 - i-1才会赢,所以赢得概率为(i-1)/n;
printf("%.10lf\n",ans);
return 0;
}