Uva10288 coupons expectation + score Calculation

Source: Internet
Author: User

Formula E (x) = n Σ 1/I

Because when K cards are different, the expectation for different cards is (n-k)/n. The probability of 1 is N/(n-k) then, add one to n.

Problem F

Coupons

Input:Standard Input

Output:Standard output

Time limit:2 seconds

Memory limit:32 MB

 

Coupons in cereal boxes are numbered1ToN, And a set of one of each is required for a prize (a cereal box, of course ). with one coupon per box, how many boxes on average are required to make a complete setNCoupons?

Input

Input consists of a sequence of lines each containing a single positive integerN, 1<=N<= 33, Giving the size of the set of coupons. input is terminated by end of file.

Output

For each input line, output the average number of boxes required to collect the complete setNCoupons. If the answer is an integer number, output the number. If the answer is not integer, then output the integer part of
Answer followed by a space and then by the proper fraction in the format shown below. The fractional part shoshould be irw.cile. There shoshould be no trailing spaces in any line of output.

Sample Input
 
2
 
5
 
17
Sample output
 
3
5
 
11 --
 
12
 
340463
 
58 ------
 
720720
 
(Math lovers 'contest, Source: University of Alberta Local contest)

 

# Include <iostream> # include <cstring> # include <string> # include <algorithm> # include <cstdio> # include <cassert> using namespace STD; typedef long ll; ll gcd (ll a, LL B) {return B = 0? A: gcd (B, A % B);} struct fraction {long num; long den; fraction (long num = 0, long den = 1) {If (Den <0) {num =-num; den =-den;} long G = gcd (ABS (Num), Den ); this-> num = num/g; this-> den = den/g;} fraction operator + (const fraction & O) const {return fraction (Num * o. den + den * o. num, den * o. den);} fraction operator-(const fraction & O) const {return fraction (Num * o. den-den * o. num, den * o. den);} FRA Ction operator * (const fraction & O) const {return fraction (Num * o. num, den * o. den);} fraction operator/(const fraction & O) const {return fraction (Num * o. den, den * o. num);} bool operator <(const fraction & O) const {return num * o. den <den * o. num;} bool operator = (const fraction & O) const {return num * o. den = den * o. num ;}; int N; int main () {While (CIN >>n) {fraction ans (n, 1); fraction TMP ); for (INT I = 1; I <= N; I ++) TMP = TMP + fraction (1, I); ans = ans * TMP; long a, B, c; A = ans. num; B = ans. den; if (a/B! = 0) {long GD = gcd (a, B); A/= Gd; B/= Gd; C = A/B; A = a-c * B ;} else C = 0; if (a = 0) printf ("% LLD \ n", c); else {int L1, L2, L3; long T1 = C, t2 = A, T3 = B; L1 = 0; while (T1) {t1/= 10; L1 ++;} L2 = 0; while (T2) {T2/= 10; L2 ++;} l3 = 0; while (T3) {T3/= 10; L3 ++;} If (L1! = 0) {for (INT I = 0; I <= L1; I ++) printf (""); printf ("% LLD \ n", ); printf ("% LLD", c); int Len = max (L2, L3); For (INT I = 0; I <Len; I ++) printf ("-"); printf ("\ n"); For (INT I = 0; I <= L1; I ++) printf (""); printf ("% LLD \ n", B);} else {printf ("% i64d \ n", a); int Len = max (L2, L3 ); for (INT I = 0; I <Len; I ++) printf ("-"); printf ("\ n"); printf ("% i64d \ n ", b) ;}}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.