Uva 138-Street Numbers(佩爾方程)

來源:互聯網
上載者:User

標籤:http   ar   io   os   sp   for   on   bs   cti   

題目連結:點擊開啟連結

題意: 一條街上有n個房子編號從1到n 設某人的房子編號為k 求滿足 1+2+3+..(k-1)=(k+1)+...+n 的10組n,k值

兩邊求和化簡得 n^2+n-2k^2=0;  兩邊同乘4  -> 4n^2+4n+1-8k^2=1;  -> (2n+1)^2-2(2k)^2=1;

令 x=2n+1 y=2k 得 x^2-2y^2=1; 形如 x^2-ny^2=1 (n為任意正整數) 的方程稱為佩爾方程,很容易求出其最小解 (x0,y0) 

然後 xi=x0*x(i-1)+n*y0*y(i-1) 

        yi=y0*x(i-1)+x0*y(i-1) ;遞推可得方程所有解

 

#include <algorithm>#include <iostream>#include <cstring>#include <cstdlib>#include <string>#include <cctype>#include <vector>#include <cstdio>#include <cmath>#include <queue>#include <stack>#include <map>#include <set>#define maxn 10000002#define _ll __int64#define ll long long#define INF 0x3f3f3f3f#define Mod 10000007#define pp pair<int,int>#define ull unsigned long longusing namespace std;int main(){int x[11]={3},y[11]={2};for(int i=1;i<=10;i++){x[i]=x[i-1]*x[0]+2*y[i-1]*y[0];y[i]=x[i-1]*y[0]+y[i-1]*x[0];int n=(x[i]-1)/2,k=y[i]/2;printf("%10d%10d\n",k,n);}return 0;}

Uva 138-Street Numbers(佩爾方程)

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.