http://poj.org/problem?id=1320

题意很简单,有序列 1,2,3...(a-1),a,(a+1)...b  要使以a为分界的 前缀和 和 后缀和 相等 求a,b

因为序列很特殊所以我们用数学方法就可以解决 :

求和:  a*(a-1)/2 = (a+1+b)(b-a)/2

化简: 2a2  = b+ b

两边乘4,构造完全平方项 (2b+1)2 - 8a2  = 1

令 x = 2*b+1;

y = a;

我们就得到了一个形如Pell方程x- Dy2  = 1  的式子 x- 8y2  = 1

这题就是求Pell方程的第K个解 , 因为方程已经告诉你了

所以我们可以目测出最小解以用来构造矩阵来求出后面的解

下面就是构造系数矩阵的方法:


已知Pell方程为 x- Dy2  = 1

为了得到第k个解,我们需要构造系数矩阵

为了得到系数矩阵,我们必须知道该方程的最小特解 x0,y0

于是我们就能得到系数矩阵:

xk y就是Pell方程的第k个解


对于Pell方程最小特解的求法,可以参照我上一篇 http://www.cnblogs.com/Felix-F/p/3222741.html

当然这题一眼就能看出最小特解为x=3,y=1

用矩阵快速幂小加了一下速                   (应该是逗比了..这样反而复杂度高了....直接记录各层次的矩阵就行...


struct matrix
{
LL ma[][];
};
int n = ;
matrix operator * (matrix a,matrix b)
{
matrix temp;
memset(temp.ma,,sizeof(temp.ma));
for(int i = ; i < n ; i++)
for(int j = ; j < n ; j++)
for(int k = ; k < n ; k++)
temp.ma[i][j] = temp.ma[i][j] + (a.ma[k][i] * b.ma[j][n-k-]);
return temp;
}
matrix operator + (matrix a,matrix b)
{
for(int i = ; i < n ; i++)
for(int j = ; j < n ; j++)
a.ma[i][j] = (a.ma[i][j] + b.ma[i][j]) ;
return a;
}
matrix m_pow(matrix a,int n)
{
if(n == ) return a;
matrix temp = m_pow(a,n/);
if(n & ) return temp * temp * a;
else return temp * temp ;
}
int main()
{
matrix a;
a.ma[][] = ;
a.ma[][] = ;
a.ma[][] = ;
a.ma[][] = ;
for(int i = ;i <= ; i++)
{
matrix tmp = m_pow(a,i);
LL s1 = tmp.ma[][] * + tmp.ma[][] * ;
LL b = (s1-)/;
LL s2 = tmp.ma[][] * + tmp.ma[][] * ;
LL a = s2;
printf("%10.lld%10.lld\n",a,b);
}
return ;
}

POJ 1320 Street Numbers Pell方程的更多相关文章

  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: 2529   Accepted: 140 ...

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

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

  4. POJ 1320:Street Numbers

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

  5. POJ 2427 Smith's Problem Pell方程

    题目链接 :  http://poj.org/problem?id=2427 PELL方程几个学习的网址: http://mathworld.wolfram.com/PellEquation.html ...

  6. Pell方程(求形如x*x-d*y*y=1的通解。)

    佩尔方程x*x-d*y*y=1,当d不为完全平方数时,有无数个解,并且知道一个解可以推其他解. 如果d为完全平方数时,可知佩尔方程无解. 假设(x0,y0)是最小正整数解. 则: xn=xn-1*x0 ...

  7. hdu2281&&POJ1320——Pell方程

    hdu2281 输入一个 $N$,求最大的 $n$($n \leq N$)和 $x$,使得 $x^2 = \frac{1^2+2^2+...+n^2}{n}$. 分析: 将右边式子的分子求和化简,有: ...

  8. Pell方程及其一般形式

    一.Pell方程 形如x^2-dy^2=1的不定方程叫做Pell方程,其中d为正整数,则易得当d是完全平方数的时候这方程无正整数解,所以下面讨论d不是完全平方数的情况. 设Pell方程的最小正整数解为 ...

  9. hdu3293(pell方程+快速幂)

    裸的pell方程. 然后加个快速幂. No more tricks, Mr Nanguo Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: ...

随机推荐

  1. bzoj 2120 数颜色 题解

    转载请注明:http://blog.csdn.net/jiangshibiao/article/details/23990489 [原题] 2120: 数颜色 Time Limit: 6 Sec  M ...

  2. ubuntu 下安装eclipse &amp;java环境配置

    前面有一篇的博客写的是ubuntu下安装eclipse和java环境的配置.当时是安装网上的攻略进行的 ,当然也是能够成功的. 近期把那台电脑送人了 ,仅仅好在自己的这台电脑上又一次安装一次了 ,唯一 ...

  3. vue17 $watch 监听数据变化

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  4. shrio int配置

    之前章节我们已经接触过一些INI配置规则了,如果大家使用过如Spring之类的IoC/DI容器的话,Shiro提供的INI配置也是非常类似的,即可以理解为是一个IoC/DI容器,但是区别在于它从一个根 ...

  5. Gym - 100625E Encoded Coordinates 矩阵快速幂

    题意: 一直TLE我也是醉了,,不爽! #include <iostream> #include <cstdio> #include <fstream> #incl ...

  6. 批处理实现添加java环境变量

    作者:朱金灿 来源:http://blog.csdn.net/clever101 从网上搜了一些资料,再修改测试,终于通过了win7系统的测试.代码如下: @echo off rem 本批处理文件目的 ...

  7. BFS(广度优先搜索)

    Catch That Cow Farmer John has been informed of the location of a fugitive cow and wants to catch he ...

  8. 在Navicat中如何新建数据库和表并做查询

    上一篇文章,小编给大家分享了在Navicat中如何远程连接数据库,没有来得及上车的小伙伴可以戳这篇文章:在Ubuntu14.04中配置mysql远程连接教程.今天小编给大家分享一下如何在Navicat ...

  9. 重写prototype原型后哪些东西改变了

    参考<JavaScript高级教程>实例看: 1.重写原型对象后,首先原型对象的constructor属性值(constructor的指向)会发生改变. function Person() ...

  10. Swift学习笔记(1)--基本语法

    1.分号; 1>Swift不要求每个语句后面跟一个分号作为语句结束的标识,如果加上也可以,看个人喜好 2>在一行中写了两句执行语句,需要用分号隔开,比如 let x = 0; printl ...