找回密码
 欢迎注册
楼主: nyy

[提问] 本原勾股数接龙

[复制链接]
发表于 2023-12-12 12:03:12 | 显示全部楼层
nyy 发表于 2023-12-12 09:07
如果接龙的时候,要求里面至少一个素数。比如你的
{88621, 55980, 104821}, {104821, 4012260, 4013629}, ...
  1. NestWhileList[
  2. Values@Solve[
  3.      x == #[[-1]] && x^2 + y^2 == z^2 && GCD[x, y] == 1 &&
  4.       z > y > 0, {x, y, z}, Integers][[1]] &, {5, 12, 13},
  5. Total@Boole[PrimeQ@#] > 0 &]
复制代码


{{5,12,13},{13,84,85},{85,132,157},{157,12324,12325},{12325,89892,90733}}
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2023-12-12 12:04:20 | 显示全部楼层
  1. NestWhileList[Values@Solve[x==#[[-1]]&&x^2+y^2==z^2&&GCD[x,y]==1&&z>y>0,{x,y,z},Integers][[1]]&,{3,4,5},Total@Boole[PrimeQ@#]>0&]
复制代码


{{3,4,5},{5,12,13},{13,84,85},{85,132,157},{157,12324,12325},{12325,89892,90733}}

点评

nyy
也许x==#[[-1]]这个改一下能实现  发表于 2023-12-12 15:27
nyy
{12325,89892,90733}这个后面进行不下去了吗?  发表于 2023-12-12 13:08
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2024-5-15 09:14:37 | 显示全部楼层
2024-05-15 08:48:52
(3, 4, 5)
(5, 12, 13)
(13, 84, 85)
(85, 132, 157)
(157, 12324, 12325)
(12325, 89892, 90733)
(90733, 2447844, 2449525)
(2449525, 28350372, 28455997)
(28455997, 295742791596, 295742792965)
(295742792965, 171480834409712412, 171480834409967437)
(171480834409967437, 633511848768467916, 656310093705697045)
(656310093705697045, 1616599508725767821225590810932, 1616599508725767821225590944157)
(1616599508725767821225590944157, 4158520496012961741299012805876, 4461691012090851100342993272805)
(4461691012090851100342993272805, 115366949386695884000892071516523067413910188, 115366949386695884000892071602798585632943213)
(115366949386695884000892071602798585632943213, 12002377162350258332845040847431429240490926601988390284, 12002377162350258332845595301471273220420939451301220405)
(12002377162350258332845595301471273220420939451301220405, 126720402261800539492024827466343006456415186761962004950492895882898948, 126720402261800539492024827466343574861561382910754310805949624338094973)
(126720402261800539492024827466343574861561382910754310805949624338094973, 228034970321525477033478437478475683098735639410761353905175525169111708972897659575652924964, 228034970321525477033478437478475683098735674620405573717049066152557390539189785244849203205)
用时 145.063828 秒


补充内容 (2024-5-16 09:42):
2024-05-16 09:28:00
(228034970321525477033478437478475683098735674620405573717049066152557390539189785244849203205, 70491794082844673202103278194318494529012587234081105546263342555712019695590672567271388145972, 70492162918766117405060956999102757878171113516181672148798433861635911212649867061707390199053)
用时 755.370965 秒

补充内容 (2024-5-16 12:40):
2024-05-16 12:39:08
(70492162918766117405060956999102757878171113516181672148798433861635911212649867061707390199053, 2088080193373219581513222265788687232160717309488882845962269786867082748931137814742302722298196640303295088196, 2088080193373219581513222265788688422044383831507621340552019591764257699450735778887334363315822550605004290965)

点评

哦!还要代码。  发表于 2024-5-15 09:25
nyy
代码呢?  发表于 2024-5-15 09:16
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2024-5-15 09:29:02 | 显示全部楼层
  1. # 本原勾股数接龙
  2. from sympy import factorint
  3. def jie_long(b=3):
  4.     u, v = (b + 1) // 2, (b - 1) // 2
  5.     Min = u ** 2 + v ** 2

  6.     for c in factorint(b):
  7.         d = b // c
  8.         i, j = (c + d) // 2, abs(c - d) // 2
  9.         k = i ** 2 + j ** 2
  10.         if k < Min:
  11.             u, v, Min = i, j, k

  12.     print(f'({abs(u ** 2 - v ** 2)}, {2 * u * v}, {k})')
  13.     return k
复制代码

循环执行若干次。

点评

应该返回Min,碰巧最后一个k最小。  发表于 2024-5-15 09:38
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2024-5-15 10:07:47 | 显示全部楼层
不限制最小,那么就可以很容易递归构造,可以知道必然无穷无限
? u=2;v=1;
? for(x=1,10, U=(u^2+v^2+1)/2;V=(u^2+v^2-1)/2;u=U;v=V;print(u^2-v^2 "," 2*u*v "," u^2+v^2))
5,12,13
13,84,85
85,3612,3613
3613,6526884,6526885
6526885,21300113901612,21300113901613
21300113901613,226847426110843688722000884,226847426110843688722000885
226847426110843688722000885,25729877366557343481074291996721923093306518970391612,25729877366557343481074291996721923093306518970391613
25729877366557343481074291996721923093306518970391613,331013294649039928396936390888878360035026305412754995683702777533071737279144813617823976263475290370884,331013294649039928396936390888878360035026305412754995683702777533071737279144813617823976263475290370885
331013294649039928396936390888878360035026305412754995683702777533071737279144813617823976263475290370885,54784900617206062846820468583349372562388728735161829255894735883217384052453987268664236809164877269859097474567984739516975948612635461161507766858920689912820154069522660952033478909299656771083000427841612,54784900617206062846820468583349372562388728735161829255894735883217384052453987268664236809164877269859097474567984739516975948612635461161507766858920689912820154069522660952033478909299656771083000427841613
54784900617206062846820468583349372562388728735161829255894735883217384052453987268664236809164877269859097474567984739516975948612635461161507766858920689912820154069522660952033478909299656771083000427841613,1500692667818572622928436696728586034769448280147464726353368783536748476474400466407448549679639472454986120214773884139043751804516562703905522786921452055548775397792172060973375592551323900399670968836768206193798999049332014146597595705864255753847966680994896463920097666188390850463692957570071204678522299907129458742675835546773340266827163074981576040462530186420620448794191288742297786522568403222907220884,1500692667818572622928436696728586034769448280147464726353368783536748476474400466407448549679639472454986120214773884139043751804516562703905522786921452055548775397792172060973375592551323900399670968836768206193798999049332014146597595705864255753847966680994896463920097666188390850463692957570071204678522299907129458742675835546773340266827163074981576040462530186420620448794191288742297786522568403222907220885

点评

nyy
你至少也带个空行分隔一下上下两行的结果  发表于 2024-5-15 10:10
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2024-5-15 10:18:39 | 显示全部楼层
如果要求最小解,那么
假设$u^2+v^2$分解为$U^2-V^2=(U-V)(U+V)$,我们要求$2UV>U^2-V^2$, 可以得出$(U+V)>(1+\sqrt{2})(U-V)$
也就是需要找出$u^2+v^2$的最大的小于$sqrt{\frac{u^2+v^2}{1+\sqrt{2}}}$的因子作为U-V。
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
发表于 2024-5-15 13:18:28 | 显示全部楼层
  1. Partition[Flatten@NestList[Values@Solve[#[[-1]]^2+y^2==z^2,{y,z},PositiveIntegers][[1]]&,{3},20],3,2]
复制代码


{{3,4,5},{5,12,13},{13,84,85},{85,132,157},{157,12324,12325},{12325,1836,12461},{12461,105552,106285},{106285,255084,276341},{276341,197580,339709},{339709,10358340,10363909},{10363909,13775220,17238541},{17238541,1936434780,1936511509},{1936511509,51299286012,51335823965},{51335823965,123205977516,133473142309},{133473142309,862441842612,872709007405},{872709007405,1310543298204,1574530008629},{1574530008629,667510076211780,667511933218429},{667511933218429,207181940072172,698925273030725},{698925273030725,110912831751840,707670964169285},{707670964169285,1698410314006284,1839944506840141}}

点评

很简单的代码,一目了然啊。难道非要加个注释“循环20次”?  发表于 2024-5-15 13:30
nyy
代码可读性太低了,不忍直视  发表于 2024-5-15 13:22
毋因群疑而阻独见  毋任己意而废人言
毋私小惠而伤大体  毋借公论以快私情
您需要登录后才可以回帖 登录 | 欢迎注册

本版积分规则

小黑屋|手机版|数学研发网 ( 苏ICP备07505100号 )

GMT+8, 2024-12-22 23:36 , Processed in 0.047231 second(s), 22 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表