一.概述 MOD(取模)运算配合质数的特性,可以实现一种简单的哈希算法. 二.基于的定理 在理解如何实现mod哈希前应当了解一些数学的定理: 1.x mod y = z ,实际上是x除以y的余数y的意思: 2.假设 x / y = z ,即 x 是被除数,y 是除数,z 是商: 3.除法规定:除数不能为0,但是被除数可以: 4.mod运算与/规则是一致的,只不过最后的结果z,mod是余数: 5.质数是只能被0和自身整除的数: 三.算法 x mod y = z 如果理解用到的基本数学定理,那么这个…
B-Casting Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 449 Accepted Submission(s): 223 Problem Description Casting around for problems leads us to combine modular arithmetic with differen…
这是一篇嘲讽我之前的自己采用笨重愚蠢思想去解决问题的日志. RSA 加密与解密涉及到 a ^ b mod c 的问题,如何计算这个值呢? 我会选择 pow(a, b) % c, 事实上在写RSA的时候确实是这么干的,但现在看来真心愚蠢, 因为我为此不得不去实现了一个自己的大数四则运算库,也就是以数组为数(BigNum),而对于mod运算只需要换算为 A % B = A - ( A / B ) * B , 好吧,我自认为轮子准备充分了, 很快就写完了,也觉得很满意,也没什么不合适的地方,但现在开始…
D Tree Problem Description There is a skyscraping tree standing on the playground of Nanjing University of Science and Technology. On each branch of the tree is an integer (The tree can be treated as a connected graph with N vertices, while each br…
Description Given n different objects, you want to take k of them. How many ways to can do it? For example, say there are 4 items; you want to take 2 of them. So, you can do it 6 ways. Take 1, 2 Take 1, 3 Take 1, 4 Take 2, 3 Take 2, 4 Take 3, 4 Input…
题目链接:http://lightoj.com/volume_showproblem.php?problem=1102 As I am fond of making easier problems, I discovered a problem. Actually, the problem and k=. There are solutions. They are . . . . . . . . . . . . . . . As I have already told you that I us…
gcd(欧几里得算法辗转相除法): gcd ( a , b )= d : 即 d = gcd ( a , b ) = gcd ( b , a mod b ):以此式进行递归即可. 之前一直愚蠢地以为辗转相除法输进去时 a 要大于 b ,现在发现事实上如果 a 小于 b,那第一次就会先交换 a 与 b. #include<stdio.h> #define ll long long ll gcd(ll a,ll b){ ?a:gcd(b,a%b); } int main(){ ll a,b; wh…
RSA Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 2353 Accepted Submission(s): 1677 Problem Description RSA is one of the most powerful methods to encrypt data. The RSA algorithm is describ…
Description Assuming a finite – radius “ball” which is on an N dimension is cut with a “knife” of N-1 dimension. How many pieces will the “ball” be cut into most?However, it’s impossible to understand the following statement without any explanation.L…
拓展欧几里得: 当 gcd ( a , b )= d 时,求绝对值和最小的 x , y 使得 x * a + y * b = d : d = gcd ( a , b ) = gcd ( b , a mod b ): 设: x1 * a + y1 * b = d : ① x2 * b + y2 * ( a mod b ) = d : ② 因为 a mod b = a - ( a / b )* b: ③(除法为整除) 将③代入①整理得: y2 * a + ( x2 - ( a / b ) * y2…
Problem Description Farmer John keeps a website called ‘FansBlog’ .Everyday , there are many people visited this blog.One day, he find the visits has reached P , which is a prime number.He thinks it is a interesting fact.And he remembers that the vis…