数论
jia_zheng
这个作者很懒,什么都没留下…
展开
-
Happy 2006
Two positive integers are said to be relatively prime to each other if the Great Common Divisor (GCD) is 1. For instance, 1, 3, 5, 7, 9…are all relatively prime to 2006. Now your job is easy: for the g原创 2016-12-06 15:10:29 · 393 阅读 · 0 评论 -
Prime Test
应用:Miller_Rabin算法 和Pollard_rho 算法Given a big integer number, you are required to find out whether it's a prime number. Input The first line contains the number of test cases T (1 <= T <= 20 ), th原创 2016-12-05 22:37:46 · 295 阅读 · 0 评论 -
素数测试(Miller-Rabin测试)
思想参照:[http://www.matrix67.com/blog/archives/234] 看了这位大牛的博客,觉得豁然开朗,于是自己敲一遍以加深印象。 1.素数的个数无限多且不存在最大的素数 证明反证法:假设存在最大的素数P,则我们可以得到一个新的数为所有的素数向乘加一,即2*3*5*7*……*P+1, 显然它不能被任一素数整除(所有的素数除它都余一),这说明我们找到了一原创 2016-12-04 20:44:27 · 1223 阅读 · 0 评论 -
拓展欧几里得算法
在介绍拓展欧几里得算法之前,先说一下欧几里得算法: 欧几里得算法又称辗转相除法,由于计算两个整数a,b的最大公约数。 基本算法:设a=qb+r,其中a,b,q,r都是整数,则gcd(a,b) = gcd(b,a%b)代码如下:int gcd (int a, int b) { if (b == 0) return a; else return gcd原创 2017-01-23 15:38:24 · 502 阅读 · 0 评论 -
hdu 3037 Saving Beans (卢卡斯定理)
Problem Description Although winter is far away, squirrels have to work day and night to save beans. They need plenty of food to get through those long cold days. After some time the squirrel family t原创 2017-03-02 20:13:41 · 262 阅读 · 0 评论 -
POJ 1061 青蛙的约会
Description两只青蛙在网上相识了,它们聊得很开心,于是觉得很有必要见一面。它们很高兴地发现它们住在同一条纬度线上,于是它们约定各自朝西跳,直到碰面为止。可是它们出发之前忘记了一件很重要的事情,既没有问清楚对方的特征,也没有约定见面的具体位置。不过青蛙们都是很乐观的,它们觉得只要一直朝着某个方向跳下去,总能碰到对方的。但是除非这两只青蛙在同一时间跳到同一点上,不然是永远都不可能碰面的。为了帮原创 2017-02-27 14:33:19 · 293 阅读 · 0 评论