Street Numbers
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 2529   Accepted: 1406

Description

A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of the street. Every evening she walks her dog by leaving her house and randomly turning left or right and walking to the end of the street and back. One night she adds up the street numbers of the houses she passes (excluding her own). The next time she walks the other way she repeats this and finds, to her astonishment, that the two sums are the same. Although this is determined in part by her house number and in part by the number of houses in the street, she nevertheless feels that this is a desirable property for her house to have and decides that all her subsequent houses should exhibit it. 
Write a program to find pairs of numbers that satisfy this condition. To start your list the first two pairs are: (house number, last number):

         6         8

        35        49

Input

There is no input for this program.

Output

Output will consist of 10 lines each containing a pair of numbers, in increasing order with the last number, each printed right justified in a field of width 10 (as shown above).

Sample Input


Sample Output

         6         8
35 49

Source

 
题目要求解1+2+3+...+n=(n+1)+....+m.
要使1+2+3+...+n=(n+1)+....+m.那么n(n+1)/2=(m-n)(n+n+1)/2,即(2m+1)^2-8n^2=1.令x=2m+1,y=n,有x^2-8y^2=1.因此就变成解佩尔方程,而x1=3,y1=1.根据迭代公式:
xn=xn-1*x1+d*yn-1*y1
yn=xn-1*y1+yn-1*x1.

已知x1=3,y1=1;

有佩尔方程的迭代公式:x[n]=x[n-1]*x1+d*y[n-1]*y1.   y[n]=y[n-1]*y1+yn-1]*x1

故有:x[n+1]=3x[n]+8y[n];

y[n+1]=x[n]+3y[n];

就可以求出前十组解。
#include<stdio.h>
#include<math.h>
int main()
{
int x1=,y1=,d=,x,y,px=,py=;
for(int i=;i<=;i++)
{
x=x1*px+d*y1*py;
y=y1*px+x1*py;
printf("%10d%10d\n",y,(x-)/);
px=x;py=y;
}
return ;
}

Pell方程,由费马提出,但后来欧拉误记为佩尔提出,并写入他的著作中。后人多称佩尔方程。

设d是正整数,且非平方数。
下面的不定方程称为佩尔(Pell)方程:
(1)一定有无穷多组正整数解
这是初等数论中最经典的内容之一。
 
 
 
 
 

POJ 1320 Street Numbers 解佩尔方程的更多相关文章

  1. POJ 1320 Street Numbers 【佩尔方程】

    任意门:http://poj.org/problem?id=1320 Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Su ...

  2. POJ 1320 Street Numbers(佩尔方程)

    Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 3078   Accepted: 1725 De ...

  3. POJ 1320 Street Numbers Pell方程

    http://poj.org/problem?id=1320 题意很简单,有序列 1,2,3...(a-1),a,(a+1)...b  要使以a为分界的 前缀和 和 后缀和 相等 求a,b 因为序列很 ...

  4. POJ1320 Street Numbers【佩尔方程】

    主题链接: http://poj.org/problem?id=1320 题目大意: 求解两个不相等的正整数N.M(N<M),使得 1 + 2 + - + N = (N+1) + - + M.输 ...

  5. [NBUT 1224 Happiness Hotel 佩尔方程最小正整数解]连分数法解Pell方程

    题意:求方程x2-Dy2=1的最小正整数解 思路:用连分数法解佩尔方程,关键是找出√d的连分数表示的循环节.具体过程参见:http://m.blog.csdn.net/blog/wh2124335/8 ...

  6. POJ 1320:Street Numbers

    Street Numbers Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 2753   Accepted: 1530 De ...

  7. HDU 3292 【佩尔方程求解 && 矩阵快速幂】

    任意门:http://acm.hdu.edu.cn/showproblem.php?pid=3292 No more tricks, Mr Nanguo Time Limit: 3000/1000 M ...

  8. 2010辽宁省赛G(佩尔方程)

    #include <iostream> #include <stdio.h> #include <string.h> #include <algorithm& ...

  9. C语言之基本算法26—佩尔方程求解

    //穷举法! /* ====================================================== 题目:求佩尔方程x*x-73*y*y=1的解. =========== ...

随机推荐

  1. AR技术介绍(Located in Android)

    一,什么是AR 在说AR技术之前,先来说说VR. 虚拟现实(VR:Virtual Reality)是采用以计算机技术为核心的技术,生成逼真的视,听,触觉等一体化的虚拟环境,用户借助必要的设备以自然的方 ...

  2. 10 TCP 传输控制协议 UDP区别

    1.tcp和udp区别 2.TCP通信模型 生活中的电话机 如果想让别人能更够打通咱们的电话获取相应服务的话,需要做一下几件事情: 买个手机 插上手机卡 设计手机为正常接听状态(即能够响铃) 静静的等 ...

  3. mutation与vuex区别

    vuex- action   1.当点发送过快,页面中渲染的内容与state中的数据不一致,vuex里面的state变得慢,且不持续更新 2.action中是可以做到页面中state中数据保持一致 责 ...

  4. springmvc基础篇—使用注解方式为前台提供数据

    一.新建一个Controller package cn.cfs.springmvc.service; import java.util.ArrayList; import java.util.Hash ...

  5. XPivot 用户手册及版本更新公示

    此文仅介绍XPivot的通用功能,如有对项目中定制的高级功能感兴趣的可留言讨论 XPivot当前版本v2.2 [2015-04-20发布] v2.1 下载链接: http://pan.baidu.co ...

  6. 自动化测试元素查找利器firepath介绍

    自动化测试查找元素和确定元素xpath路径是否正确在业界有个很好的工具就是firefox 浏览器的 firepath 问题: firefox 最新版本已经不支持firebug和firepath这两个插 ...

  7. Linux开发C语言规范

    -Iinclude:找头文件目录 ,获取头文件的目录 -C:创建.o文件 .h:文件用来声明函数,即写一个函数名. 如 int add(); int div(); int mul(); .c:文件定义 ...

  8. URAL 1736 Chinese Hockey(网络最大流)

    Description Sergey and Denis closely followed the Chinese Football Championship, which has just come ...

  9. Android Service 服务(三)—— bindService与remoteService

    (转自:http://blog.csdn.net/ithomer/article/details/7366396)   一.bindService简介 bindService是绑定Service服务, ...

  10. android自定义View绘制圆形头像与椭圆头像

    要实现这两种效果,需要自定义View,并且有两种实现方式.   第一种: public class BitmapShaders extends View {     private  BitmapSh ...