2010辽宁省赛G(佩尔方程)
bool PQA(LLI D, LLI &p, LLI &q) {//来自于PQA算法的一个特例
LLI d = sqrt(D);
if ((d + 1) * (d + 1) == D) return false;
if (d * d == D) return false;
if ((d - 1) * (d - 1) == D) return false;//这里是判断佩尔方程有没有解
LLI u = 0, v = 1, a = int(sqrt(D)), a0 = a, lastp = 1, lastq = 0;
p = a, q = 1;
do {
u = a * v - u;
v = (D - u * u) / v;
a = (a0 + u) / v;
LLI thisp = p, thisq = q;
p = a * p + lastp;
q = a * q + lastq;
lastp = thisp;
lastq = thisq;
} while ((v != 1 && a <= a0));//这里一定要用do~while循环
p = lastp;
q = lastq;
//这样求出后的(p,q)是p2 – D * q2 = (-1)k的解,也就是说p2 – D * q2可能等于1也可能等于-1,如果等于1,(p,q)就是解,如果等于-1还要通过(p2 + D * q2,2 * p * q)来求解,如下
if (p * p - D * q * q == -1) {
p = lastp * lastp + D * lastq * lastq;
q = 2 * lastp * lastq;
}
return true;
}
*/
2010辽宁省赛G(佩尔方程)的更多相关文章
- ZOJ 1985 Largest Rectangle in a Histogram(刷广告)2010辽宁省赛
Largest Rectangle in a Histogram Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 21204 ...
- NBUT 1221 Intermediary 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB It is widely known that any two strangers can get to know ...
- NBUT 1224 Happiness Hotel 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The life of Little A is good, and, he managed to get enoug ...
- NBUT 1222 English Game 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB This English game is a simple English words connection gam ...
- NBUT 1225 NEW RDSP MODE I 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A has became fascinated with the game Dota recent ...
- NBUT 1218 You are my brother 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Little A gets to know a new friend, Little B, recently. On ...
- NBUT 1220 SPY 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB The National Intelligence Council of X Nation receives a ...
- NBUT 1219 Time 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Digital clock use 4 digits to express time, each digit ...
- NBUT 1223 Friends number 2010辽宁省赛
Time limit 1000 ms Memory limit 131072 kB Paula and Tai are couple. There are many stories betwee ...
随机推荐
- Java图像处理最快技术:ImageJ 学习第一篇
ImageJ是世界上最快的纯Java的图像处理程序. 它能够过滤一个2048x2048的图像在0.1秒内(*). 这是每秒40万像素!ImageJ的扩展通过使用内置的文本编辑器和Java编译器的Ima ...
- Table control 相关
转:晚上回去有时间看看 http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbac1d35c111d1829f0000e829fbfe/frameset. ...
- ME01 创建货源清单
[转自 http://blog.sina.com.cn/s/blog_6466e5f70100ix3p.html ] SAP中采购货源清单创建的方法有以下几种: 1.ME01 手动逐个创建. 2.ME ...
- 字符串的朴素模式和KMP模式匹配
先复习一下字符串指针: #include <iostream> #include <string.h> using namespace std; int main() { ch ...
- Spring Boot 支持多种外部配置方式
Spring Boot 支持多种外部配置方式 http://blog.csdn.net/isea533/article/details/50281151 这些方式优先级如下: 命令行参数 来自java ...
- MySQL——事务
核心知识: 1.什么是事务?一组原子性的SQL查询语句 2.事务的四种属性:ACID 3.四种隔离级别:读取未提交内容.读取提交内容.重复读.串行化. 4.什么是幻读?幻读有那些解决办法?连续读取同一 ...
- IOS AFNetWorking 设置超时时间
(原创经验总结) 1.关于AF 超时的说法 系统默认的timeInterval 是60s ASI默认是10s 但是有一个说法是 AF “AFN在GET条件下设置的NSURLRequest能起作用, ...
- linux系统调用mount全过程分析【转】
本文转载自:https://blog.csdn.net/skyflying2012/article/details/9748133 系统调用本身是软中断,使用系统调用,内核也陷入内核态,异常处理,找到 ...
- cmd 环境变量设置方法详细解释
cmd设置环境变量可以方便我们bat脚本的运行,但是要注意的是变量只在当前的cmd窗口有作用(局部生效),如果想要设置持久的环境变量需要我们通过两种手段进行设置:一种是直接修改注册表,另一种是通过我的 ...
- 算法(Algorithms)第4版 练习 1.3.26
方法实现: //1.3.26 /** * remove all of the nodes in the list that have key as its item field * * @param ...