Блог пользователя hunter_of_alts

Автор hunter_of_alts, 2 года назад, По-английски

You are given a number $$$n$$$, And we have two functions, We declare $$$P(S)$$$ for a set of numbers, product of all the numbers in the set, Also we declare $$$F(S)$$$ for a set of numbers, sum of all the numbers in the set, You have the set {$$$1, 2, 3, ... , n$$$} you have to calculate

$$$\sum_{i=1}^{2^{n}-1}(F(S_i)/P(S_i))$$$

for all non empty subsequences of {$$$1, 2, 3, ... , n$$$}, in the other words you have to provide a solution that calculates sum of $$$F(S)/P(S)$$$ for all non empty subsequences.

For example the answer for $$$n = 2$$$ is this :

  • for {$$$1$$$} sum is $$$1$$$ and product of numbers in it is $$$1$$$ so $$$F($$${$$$1$$$}$$$)/P($$${$$$1$$$}$$$)$$$ is $$$1/1 = 1$$$

  • for {$$$2$$$} sum is $$$2$$$ and product of numbers in it is $$$2$$$ so $$$F($$${$$$2$$$}$$$)/P($$${$$$2$$$}$$$)$$$ is $$$2/2 = 1$$$

  • and for the last non empty subsequence {$$$1, 2$$$} sum is $$$3$$$ and product of the numbers in it is $$$2$$$ so $$$F($$${$$$1, 2$$$}$$$)/P($$${$$$1, 2$$$}$$$)$$$ is $$$3/2 = 1.5$$$

So the answer for $$$n = 2$$$ is $$$1 + 1 + 1.5 = 3.5$$$

Constraints :

$$$1 \le n \le 10^6$$$

Solution

Hope you enjoy the problem, I'll share my approach's proof after $$$24$$$ hours!

  • Проголосовать: нравится
  • +39
  • Проголосовать: не нравится

»
2 года назад, # |
  Проголосовать: нравится +18 Проголосовать: не нравится
My solution
»
2 года назад, # |
Rev. 2   Проголосовать: нравится +12 Проголосовать: не нравится

Its pretty simple! I'll try to explain as simple as possible. First, for a set $$$S_i$$$ imagine splitting $$$F(S_i)/P(S_i)$$$. For example, if my set is $$$S = \{ 1,2,3 \}$$$. Then my splitting for $$$F(S)/P(S)$$$ will be: $$$1*(\frac{1}{1*2*3}) + 2*(\frac{1}{1*2*3}) + 3*(\frac{1}{1*2*3})$$$. Every such split has some coefficient of every number from $$$1$$$ to $$$n$$$. In this example coefficients are ($$$\frac{1}{6} , \frac{1}{6},\frac{1}{6},0,0..)$$$.

What would be the coefficient of some number $$$i$$$ in my entire sum? It will be the in form $$$\sum(\frac{1}{P_j})$$$, where $$$P_j$$$ means the product of a subset having $$$i$$$. I sum this over all subsets containing $$$i$$$. So, imagine selecting some numbers from a bunch of $$$(\frac{1}{1},\frac{1}{2},\frac{1}{3},...\frac{1}{n})$$$ under the condition that $$$\frac{1}{i}$$$ must be selected, then adding them up. It is easy to see it will be $$$(1+\frac{1}{1})(1+\frac{1}{2})(1+\frac{1}{3})..(\frac{1}{i})..(1+\frac{1}{n})$$$. This is because while multiplying, every number $$$t$$$ (except $$$i$$$) has a choice of getting selected or rejected (hence, $$$1$$$ or $$$\frac{1}{t}$$$). However, we gotta select $$$\frac{1}{i}$$$, so I multiply my $$$\frac{1}{i}$$$.

So, now we got the coefficient of number $$$i$$$. Final answer will be:

$$$\sum i*Ci \text{ where,} $$$
$$$Ci = (1+\frac{1}{1})(1+\frac{1}{2})(1+\frac{1}{3})..(\frac{1}{i})..(1+\frac{1}{n})$$$

Summing this up, everything will magically cancel out! (The Aha! moment) and you'll get the result :)

»
2 года назад, # |
  Проголосовать: нравится +3 Проголосовать: не нравится

After reading this type of blogs I always think that I am very bad at mathematics.

How to be good. Anyone who can help?

»
2 года назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

nice problem