[POJ1320] Street Number
来源:互联网 发布:xp无法连接网络打印机 编辑:程序博客网 时间:2024/05/17 08:55
题目描述
求解两个不相等的正整数n,m(n < m)使得1+2+3……+n=n+(n+1)+….+m
输入格式
无输入
输出格式
输出前10组满足条件的(n,m)(从小到大),每组占一行。对于每组输出的n、m宽度为10。
样例数据
样例输入
样例输出
前两组:
6 8
35 49
题目分析
(2m+1)^2-8n^2=1
令x=2m+1,y=n,则有x^2-8y^2=1
典型佩尔方程,斗出最小解x1=3,y1=1
故由佩尔方程迭代公式得
源代码
#include<algorithm>#include<iostream>#include<iomanip>#include<cstring>#include<cstdlib>#include<vector>#include<cstdio>#include<cmath>#include<queue>using namespace std;inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj;}//n(n+1)/2=(m-n)(m+n+1)/2 即 (2m+1)^2-8n^2=1 //x(n+1)=3xn+8yn y(n+1)=xn+3ynint Limit;int main() { Limit=10; int Lastx=3,Lasty=1; for(int i=1; i<=Limit; i++) { int x=3*Lastx+8*Lasty,y=Lastx+3*Lasty; printf("%10d%10d\n",y,(x-1)/2); Lastx=x; Lasty=y; } return 0;}
也可以直接打表
#include<algorithm>#include<iostream>#include<iomanip>#include<cstring>#include<cstdlib>#include<vector>#include<cstdio>#include<cmath>#include<queue>using namespace std;inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj;}int main() { printf(" 6 8\n 35 49\n 204 288\n 1189 1681\n 6930 9800\n 40391 57121\n 235416 332928\n 1372105 1940449\n 7997214 11309768\n 46611179 65918161\n"); return 0;}
0 0
- [POJ1320] Street Number
- POJ1320 Street Numbers【佩尔方程】
- POJ1320 Street Numbers(佩尔方程)
- POJ1320 Street Numbers 佩尔方程 特殊的不定方程的应用
- POJ 1320 Street Number(佩尔方程)
- poj-1320 Street Number 佩尔方程
- Street
- poj1320(解pell方程)
- Street Numbers
- Street Race
- Seattle Street
- Street Lamps
- [JZOJ4596]street
- 关于itil_03_State Street
- Ford Street Racing 2006
- Ford Street Racing (Reloaded)
- usaco 4.3 Street Race
- Section 4.3 Street Race
- 讯为4412精英版让OTG支持HOST模式
- Spring Boot 菜鸟教程 19 后台验证 Hibernate Validation
- 【Basic Code】转义符 小结
- git常用功能及设置
- Linux网络编程之SOCKET文件传输
- [POJ1320] Street Number
- 数据结构算法中用到的存储结构
- 常用数学算式。
- 【C++】 C++标准模板库(十二) 迭代器和STL
- Proguard的Keep使用方法
- 你很烫吗?我很烫——关于栈区和静态存储区的思考
- 初探腾讯Unity手游热更新方案xlua
- eclipse配置环境变量问题
- jquery和prototype.js的区别