poj_1320_Street Numbers
2024-09-03 19:20:22
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):
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
题意 k号房子分开n栋房子,前k-1栋和等于k+1到第n栋。输出k,n。
网上题解大多瞎XX扯X,证明不完整,推导胡说八道直接给出佩尔方程。我直接暴力打印前几组找到了规律
6 8
35 49
204 288
1189 1681
到这里我就发现了,
204=35*6-6 288=204+35+49
1189=204*6-35 1681=1189+204+288
a[i]=a[i-1]*6-a[i-2]
b[i]=a[i]+a[i-1]+b[i-1]
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<cstdio>
#define N 1000010
using namespace std;
typedef long long ll;
int a[11];
int b[11];
int main()
{
// freopen("dataout.txt","w",stdout);
a[0]=6;
a[1]=35;
b[0]=8;
b[1]=49;
printf("%10d%10d\n",6,8);
printf("%10d%10d\n",35,49);
for(int i=2;i<10;i++)
{
a[i]=a[i-1]*6-a[i-2];
b[i]=a[i]+a[i-1]+b[i-1];
int x=a[i],y=b[i];
printf("%10d%10d\n",a[i],b[i]);
} }
最新文章
- Python PIP安装
- 求两圆相交部分面积(C++)
- IP地址的组成
- python 实现树结构的打印
- php开发api接口
- c#_错误处理_基础
- 使用cvs或svn从sourceforge上获取开源项目的方法[转载]
- Python 用IMAP接收邮件
- Tomcat+Servlet面试题都在这里
- 课堂小记---JavaScript(3)
- .NET Core跨平台的奥秘[中篇]:复用之殇
- Echarts自定义tootips
- [Swift]LeetCode934. 最短的桥 | Shortest Bridge
- css3选择器和伪类
- mfc添加自定义事件
- Jdk_API——1.8和Jdk_API1.6下载分享
- Docker镜像管理基础与基于容器的镜像制作示例
- 8.C#友元程序集----可访问性相关
- JVM虚拟机详解
- React文档(二)Hello World