Arranged probability
Problem 100
If a box contains twenty-one coloured discs, composed of fifteen blue discs and six red discs, and two discs were taken at random, it can be seen that the probability of taking two blue discs, P(BB) = (15/21)×(14/20) = 1/2.
The next such arrangement, for which there is exactly 50% chance of taking two blue discs at random, is a box containing eighty-five blue discs and thirty-five red discs.
By finding the first arrangement to contain over 1012 = 1,000,000,000,000 discs in total, determine the number of blue discs that the box would contain.
题解:b*(b-1) / (n*(n-1)) = 1/2
==> n^2-2b^2-n+2b = 0
==> (2n-1)^2-2(2p-1^2)= -1
==>上面的是第二型佩尔方程
==>关于第二型佩尔方程的正整数解的通用解法,好像还是一个未解决问题。
==>考虑到(1,1)为这个方程的最小解,记为(x1,y1)则第二型佩尔方程有通解公式:
==>xn=(1/2)((x1+y1sqrt(d))^(2n+1)+(x1-y1sqrt(d))^(2n+1))
==>yn=(1/(2sqrt(d)))((x1+y1sqrt(d))^(2n+1)-(x1-y1sqrt(d))^(2n+1))
==>其中,d=2.
于是,构成线性地推:
x_(n+1) = 3x_n+4y_n
y_(n+1) = 2x_n+3y_n
==>
n0=0,b0=0 and n0=1,b0=1
n(n+1) = P*n(n)+Q*b(n)+K
b(n+1) = R*n(n)+S*b(n)+L
P=3, Q=2, K=-2, R=4, S=3, L=-3
代码:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
ll n=21,b=15;
while(n<1000000000000L)
{
ll tmp_n=4*b+3*n-3;
ll tmp_b=3*b+2*n-2;
n=tmp_n;
b=tmp_b;
}
cout<<b<<endl;
return 0;
}