refactor checking pell solution
This commit is contained in:
parent
d238fe196f
commit
675b98bf17
18
cmd/pell.go
18
cmd/pell.go
|
|
@ -26,6 +26,16 @@ import (
|
|||
|
||||
var pellCoeff string
|
||||
|
||||
func isPellSolution(h, k, d *big.Int) bool {
|
||||
foo := new(big.Int).Exp(k, big.NewInt(2), nil)
|
||||
foo.Mul(d, foo)
|
||||
|
||||
bar := new(big.Int).Exp(h, big.NewInt(2), nil)
|
||||
bar.Sub(bar, foo)
|
||||
|
||||
return bar.Cmp(big.NewInt(1)) == 0
|
||||
}
|
||||
|
||||
func pell(cmd *cobra.Command, args []string) {
|
||||
d, ok := new(big.Int).SetString(pellCoeff, 10)
|
||||
if !ok {
|
||||
|
|
@ -44,13 +54,7 @@ func pell(cmd *cobra.Command, args []string) {
|
|||
|
||||
for {
|
||||
h, k := <-hch, <-kch
|
||||
foo := new(big.Int).Exp(k, big.NewInt(2), nil)
|
||||
foo.Mul(d, foo)
|
||||
|
||||
bar := new(big.Int).Exp(h, big.NewInt(2), nil)
|
||||
bar.Sub(bar, foo)
|
||||
|
||||
if bar.Cmp(big.NewInt(1)) == 0 {
|
||||
if isPellSolution(h, k, d) {
|
||||
fmt.Println(h, k)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue