题目链接
题意:
定义好数 n n n满足在区间 [ n 2 + 1 , n 2 + 2 n ] [n^2+1, n^2+2n] [n2+1,n2+2n]存在一个数 x x x满足 x ∣ n 4 x|n^4 x∣n4
给定一个正整数 m m m,求不小于 m m m的最小好数。
m ≤ 1 0 1000 m \leq 10^{1000} m≤101000
思路:
数论好题~
设 x = n 2 + a x = n^2 + a x=n2+a
则可得: n 2 + a ∣ n 4 n^2+a | n^4 n2+a∣n4
此时试着构造式子来建立 n 4 n^4 n4和 n 2 + a n^2 + a n2+a的关系,得到:
n 4 = ( n 2 + a ) 2 − a 2 − 2 a n 2 n^4 = (n^2 + a)^2 - a^2 - 2an^2 n4=(n2+a)2−a2−2an2
和
n 4 = ( n 2 + a ) ( n 2 − a ) + a 2 n^4 = (n^2 + a)(n^2 - a) + a^2 n4=(n2+a)(n2−a)+a2
因为 ( n 2 + a ) ∣ n 4 (n^2 + a) | n^4 (n2+a)∣n4,且因为 ( n 2 + a ) ∣ ( n 2 + a ) ( n 2 − a ) (n^2+a)|(n^2+a)(n^2-a) (n2+a)∣(n2+a)(n2−a)
可推出:
( n 2 + a ) ∣ n 4 − ( n 2 + a ) ( n 2 − a ) (n^2+a) | n^4 - (n^2+a)(n^2-a) (n2+a)∣n4−(n2+a)(n2−a)
利用第二个关系式 n 4 = ( n 2 + a ) ( n 2 − a ) + a 2 n^4 = (n^2 + a)(n^2 - a) + a^2 n4=(n2+a)(n2−a)+a2,得:
( n 2 + a ) ∣ a 2 (n^2+a) | a^2 (n2+a)∣a2
等价于:
a 2 = m ( n 2 + a ) a^2 = m(n^2 + a) a2=m(n2+a)
又定义式: x = n 2 + a x = n^2 + a x=n2+a
故 1 < = a < = 2 n 1 <= a <= 2n 1<=a<=2n,即 1 < = a 2 < = 4 n 2 < 4 ( n 2 + a ) 1 <= a^2 <= 4n^2 < 4(n^2 + a) 1<=a2<=4n2<4(n2+a)
故
m = 1 , 2 , 3 m = 1, 2, 3 m=1,2,3
当 m = 1 m = 1 m=1时, a 2 = n 2 + a a^2 = n^2 + a a2=n2+a
即
a ( a − 1 ) = n 2 a(a - 1) = n ^ 2 a(a−1)=n2
因 n , a n,a n,a均为整数,故无解
当 m = 2 m = 2 m=2时, a 2 = 2 n 2 + 2 a a^2 = 2n^2 + 2a a2=2n2+2a
则:
( a − 1 ) 2 − 2 n 2 = 1 (a-1)^2 - 2n^2 = 1 (a−1)2−2n2=1
令 x = a − 1 x = a - 1 x=a−1, y = n y = n y=n,则化为:
x 2 − 2 y 2 = 1 x^2 - 2y^2 = 1 x2−2y2=1
此为Pell方程的标准形式
利用连分数可以解出最小整数解,解为 ( 3 , 2 ) (3, 2) (3,2)
具体原理不再赘述,附上Python代码,输入任意的 d d d,则可以输出 x 2 − d y 2 = 1 x^2 - dy^2 = 1 x2−dy2=1的最小整数解。
def getPell(n):
j = 1
while j*j<n:
j += 1
if j*j == n:
print(j,1)
if j*j > n:
p = [0 for i in range(0, 1001)]
q = [0 for i in range(0, 1001)]
a = [0 for i in range(0, 1001)]
g = [0 for i in range(0, 1001)]
h = [0 for i in range(0, 1001)]
p[1] = q[0] = h[1] = 1
p[0] = q[1] = g[1] = 0
a[2] = j - 1
i = 2
while 1:
g[i]=-g[i-1]+a[i]*h[i-1]
h[i]=(n-g[i]*g[i])/h[i-1]
a[i+1]=(g[i]+a[2])/h[i]
p[i]=a[i]*p[i-1]+p[i-2]
q[i]=a[i]*q[i-1]+q[i-2]
if(p[i]*p[i]-n*q[i]*q[i]==1):
print(p[i], q[i])
break
i += 1
if __name__ == "__main__":
d = int(input())
getPell(d)
那应该如何推出其他的解呢,我们可以先看一种通用的解法,即将最小整数解回代:
1 = 3 2 − 2 ∗ 2 2 = ( 3 − 2 2 ) ( 3 + 2 2 ) 1 = 3^2 - 2*2^2 = (3 - 2\sqrt2)(3 + 2\sqrt2) 1=32−2∗22=(3−22)(3+22)
两边同时平方,得:
1 2 = 1 = ( 3 − 2 2 ) 2 ( 3 + 2 2 ) 2 = ( 17 − 12 2 ) ( 17 + 12 2 ) 1^2 = 1 = (3 - 2\sqrt2)^2 (3 + 2\sqrt2)^2 = (17 - 12\sqrt2) (17 + 12\sqrt2) 12=1=(3−22)2(3+22)2=(17−122)(17+122)
故第二组解为:(17, 12)
…
同理易得,对于第 k k k组解,有:
x k + 2 y k = ( 3 + 2 2 ) k x_k + \sqrt2y_k = (3 + 2\sqrt 2)^k xk+2yk=(3+22)k
则:
KaTeX parse error: No such environment: eqnarray* at position 7: \begin{̲e̲q̲n̲a̲r̲r̲a̲y̲*̲}̲x_{k+1} + y_{k…
因等式两端整数项对应相等,根号项对应相等,故:
{ x k + 1 = 3 x k + 4 y k y k + 1 = 2 x k + 3 y k \begin{cases} x_{k+1} = &3x_{k}& + &4y_{k} \\ y_{k+1} = &2x_{k}&+&3y_{k} \end{cases} {xk+1=yk+1=3xk2xk++4yk3yk
现在考虑如何推出 x , y x,y x,y单独的通项式:
KaTeX parse error: No such environment: eqnarray* at position 7: \begin{̲e̲q̲n̲a̲r̲r̲a̲y̲*̲}̲x_{k+2} &=&3x…
同理可得:
y k + 2 = 6 y k + 1 − y k y_{k+2} = 6y_{k+1} - y_k yk+2=6yk+1−yk
因为 y = n y = n y=n,故我们可以令:
n 0 = 0 , n 1 = 2 n_0 = 0, n_1 = 2 n0=0,n1=2
则:
n k = 6 n k − 1 − n k − 2 n_k = 6n_{k-1} - n_{k-2} nk=6nk−1−nk−2
故可以推出在 m = 2 m=2 m=2的情况下所有的 n n n
m = 3 m = 3 m=3时,同理可得 n n n的通项:
n 0 = 0 , n 1 = 6 n_0 = 0, n_1 = 6 n0=0,n1=6
n k = 14 n k − 1 + n k − 2 n_k = 14n_{k-1} + n_{k-2} nk=14nk−1+nk−2
故此题只需要递推出最小的不小于给定的 m m m值的 n n n即可。
代码:
m = (int)(input())
n0, n1 = 0, 2
while n1 < m:
n0, n1 = n1, 6*n1 - n0
m0, m1 = 0, 6
while m1 < m:
m0, m1 = m1, 14*m1 - m0
print(min(n1, m1))
拓展1:如何更简便地求出Pell方程某一变量的通项公式?
假设已知Pell方程:
x 2 − d y 2 = 1 x^2 - dy^2 = 1 x2−dy2=1
如果我们已经得到其最小正整数解( x 0 , y 0 x_0, y_0 x0,y0)
则对于第 k k k组解有:
x k + d y k = ( x 0 + d y 0 ) k x_k + \sqrt d y_k = (x_0 + \sqrt d y_0)^k xk+dyk=(x0+dy0)k
故可以推出:
KaTeX parse error: No such environment: eqnarray* at position 7: \begin{̲e̲q̲n̲a̲r̲r̲a̲y̲*̲}̲x_{k+1} + \sqr…
由等式两边对应系数相等,得出:
{ x k + 1 = x 0 x k + d y 0 y k y k + 1 = y 0 x k + x 0 y k \begin{cases} x_{k+1} = &x_0x_{k}& + &dy_0y_{k} \\ y_{k+1} = &y_0x_{k}&+&x_0y_{k} \end{cases} {xk+1=yk+1=x0xky0xk++dy0ykx0yk
故通项式为:
KaTeX parse error: No such environment: eqnarray* at position 7: \begin{̲e̲q̲n̲a̲r̲r̲a̲y̲*̲}̲x_{k+2} &=&x_…
同理:
y k + 2 = 2 x 0 y k + 1 − y k y_{k+2} = 2x_0y_{k+1} - y_k yk+2=2x0yk+1−yk
故递推式前的系数分别是 ( 2 x 0 , − 1 ) (2x_0, -1) (2x0,−1)
拓展2:对于非标准形式的Pell方程 x 2 − d y 2 = T x^2 - dy^2 = T x2−dy2=T ( T ≠ 1 ) (T \ne 1) (T̸=1),我们如何求出其通解呢?
(待更新)