POJ1320 Street Numbers 佩尔方程 特殊的不定方程的应用

本文通过解析一个特定数列问题,引入佩尔方程的概念并提供了解决方法。文章详细介绍了如何将数学理论应用于算法解决实际问题的过程,并通过代码实现展示了求解步骤。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

题意:求两个不相等的正整数n,m(n<m),使得1+2+……+n = (n+1) + ……+m,输出前十组答案即可,,注意输出格式 每个数占10格

解析前小广告!总是做算法,不如来个陶冶情操的文章一篇: http://www.sanwen.net/subject/3628849/

解析:

使得1+2+……+n = (n+1) + ……+m,那么 n(n+1)/2 = (m-n)(m+n+1)/2,化简 (2m+1)^2 - 8*n^2 = 1,令x = 2*m+1,y=n,那么方程可以转化为x^2 - 8*y^2 = 1,看到这里的话 这个是典型的佩尔方程,比较偏,有迭代公式可以利用 令x1 = 3,y1 = 1;

佩尔方程介绍:http://baike.baidu.com/link?url=QAt4OjP_zUgUOqTXVn78t00tC4DQR9MRHAQEyJF4YgSgndUgGaOXRcxRG9YoL5gv



#include<iostream>
#include<cstdio>
#include<list>
#include<algorithm>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<cmath>
#include<memory.h>
#include<set>

#define ll long long

#define eps 1e-8

#define inf 0xfffffff

//const ll INF = 1ll<<61;

using namespace std;

//vector<pair<int,int> > G;
//typedef pair<int,int > P;
//vector<pair<int,int> > ::iterator iter;
//
//map<ll,int >mp;
//map<ll,int >::iterator p;



int main() {

	int x0,y0,x1,y1,tmpx,tmpy,d;
	x1 = 3;
	y1 = 1;
	tmpx = 3;
	tmpy = 1;
	d = 8;
	for(int i=1;i<=10;i++) {
		x0 = tmpx * x1 + d * tmpy * y1;
		y0 = tmpx * y1 + tmpy * x1;
		printf("%10d%10d\n",y0,(x0 - 1)/2);
		tmpx = x0;
		tmpy = y0;
	}
	return EXIT_SUCCESS;
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值