题意:1~n编号的彩票,要买全,等概率条件下平均要买几张。已经买了m张时,买中剩下的概率为1-m/n,则要买的张数为1/(1-m/n)n=2,s=1+1/(1-1/2);n=3,s=1+1/(1-1/3)+1/(1-2/3)s=1+1/(1-1/n)+1/(1-2/n)+1/(1-3/n)+……+1/(1-(n-1)/n)=n/n+n/(n-1)+n/(n-2)+……+n/1=sum(n/i),i=1~nb/a+d/c=(bc+ad)/(ac)然后递推着通分,化简;输出。
///实现 sum(n/i) (i=1~n)#include#include #include #include #include #include #include using namespace std;#define LL long longLL gcd(LL a,LL b){ return b==0?a:gcd(b,a%b);}struct fen{ LL a,b;};fen& add(struct fen&a,struct fen&b){ a.a=a.a*b.b+a.b*b.a; a.b=a.b*b.b; LL t=gcd(a.a,a.b); a.a/=t; a.b/=t; return a;}int ditNum(LL a){ int cnt=0; while(a) { cnt++; a/=10; } return cnt;}int main(){ int n; LL fenz=0,fenm=0; struct fen f,f1; while(~scanf("%d",&n)) { f.a=n;f.b=1; for(int i=2;i<=n;i++) { f1.a=n;f1.b=i; f=add(f,f1); } if(f.a%f.b==0) { cout<