博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
*佩尔方程*
阅读量:3951 次
发布时间:2019-05-24

本文共 1422 字,大约阅读时间需要 4 分钟。

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, each printed right justified in a field of width 10 (as shown above).

【题意】

有m个街道,程序员的家在n点,满足1+2+...+n-1=n+1+......+m;

求n,m;

此时方程为:(2*m+1)^2-8*n^2=1;

x=2*m+1,y=n;

最小的一组解为:x1=3,y1=1;

m=(x-1)/2,n=y;

循环求出十组解即可,注意格式/

#include 
using namespace std;int main(){ ios::sync_with_stdio(false); int x,y; int x1=3,y1=1; for(int i=1;i<=10;i++) { x=x1*3+8*y1; y=x1+3*y1; cout<
<
<
<<(x-1)/2<

 

转载地址:http://xvyzi.baihongyu.com/

你可能感兴趣的文章
Linux 2.6下SPI设备模型--------基于AT91RM9200分析
查看>>
struct device 结构
查看>>
S3C2440上触摸屏驱动实例开发讲解
查看>>
一个基于linux2.6内核下S3C2410触摸屏驱动
查看>>
Linux 内核/sys 文件系统介绍
查看>>
AMBA、AHB、APB总线简介
查看>>
开关功率mos管介绍
查看>>
Porting Guide of Android Power to Marvell 2.6.24
查看>>
Android编译环境(4) - Android内核编译方法(未公开源码)
查看>>
Android Power Management
查看>>
Android对Kernel的改动汇总
查看>>
"android linux kernel" VS "standard linux kernel"
查看>>
Android电源管理概念
查看>>
老手经验谈:Linux驱动程序开发学习步骤
查看>>
6个好习惯让你做个优秀的开发者
查看>>
platform_device的注册过程分析
查看>>
linux2.6中的工作队列接口 workqueue_struct
查看>>
等待队列学习笔记
查看>>
MTK G-sensor
查看>>
linux工作队列
查看>>