Project Euler:Problem 66 Diophantine equation
2015-07-15 20:03
447 查看
Consider quadratic Diophantine equations of the form:
x2 – Dy2 = 1
For example, when D=13, the minimal solution in x is 6492 – 13×1802 = 1.
It can be assumed that there are no solutions in positive integers when D is square.
By finding minimal solutions in x for D = {2, 3, 5, 6, 7}, we obtain the following:
32 – 2×22 = 1
22 – 3×12 = 1
92 – 5×42 = 1
52 – 6×22 = 1
82 – 7×32 = 1
Hence, by considering minimal solutions in x for D ≤ 7, the largest x is obtained when D=5.
Find the value of D ≤ 1000 in minimal solutions of x for which the largest value of x is obtained.
首先要了解佩尔方程及其解法。
还要了解一些连分式的性质。
x2 – Dy2 = 1
For example, when D=13, the minimal solution in x is 6492 – 13×1802 = 1.
It can be assumed that there are no solutions in positive integers when D is square.
By finding minimal solutions in x for D = {2, 3, 5, 6, 7}, we obtain the following:
32 – 2×22 = 1
22 – 3×12 = 1
92 – 5×42 = 1
52 – 6×22 = 1
82 – 7×32 = 1
Hence, by considering minimal solutions in x for D ≤ 7, the largest x is obtained when D=5.
Find the value of D ≤ 1000 in minimal solutions of x for which the largest value of x is obtained.
首先要了解佩尔方程及其解法。
还要了解一些连分式的性质。
import math maxn=1 maxD=2 for D in range(2,1001): tmp=math.sqrt(D) tmp=int(tmp) if tmp*tmp==D: continue m=0 d=1 a=tmp #print(a) n1=1 d1=0 num=a den=1 while num*num-D*den*den!=1: m=int(a*d-m) d=int((D-m*m)/d) a=int((tmp+m)/d) n2=n1 n1=num d2=d1 d1=den num=int(a*n1+n2) den=int(a*d1+d2) #print('num = ',num) #print('den = ',den) #print ('result = ',num*num-D*den*den) if num >maxn: maxn=num maxD=D print(maxD)
相关文章推荐
- [Shell]给linux命令tee输出文件加个时间
- Linux系统平均负载
- 查看 SELinux状态及关闭SELinux
- CentOS 如何安装git server + Gitolite 【配置不成功需要再测试2015-8-20】
- linux系统编程:进程原语
- 实时处理日均50亿会话,解析Twitter Answers的架构
- nginx.conf配置说明
- linux系统编程:进程间通信-mmap
- 每天一个linux命令(60):scp命令
- CentOS 安装软件时,错误Transaction check error ... file...conflicts with file from package zzz的解决
- APACHE服务器出现No input file specified.的完美解决方案
- linux配置IP的方法
- opencv 学习记录(1)Mat IpImage
- nginx
- Linux系统防CC攻击自动拉黑IP增强版Shell脚本
- centos 6.5安装vncserver 并开启远程桌面
- [三]三种 hls 解析源码 vlc ffmpeg exoplayer
- [二]三种 hls 解析源码 vlc ffmpeg exoplayer
- [一]三种 hls 解析源码 vlc ffmpeg exoplayer
- 同一个tomcat中部署多个工程,不能访问的问题