收藏 分享(赏)

离散数学课件-第2章-3.ppt

上传人:gnk289057 文档编号:6639309 上传时间:2019-04-19 格式:PPT 页数:54 大小:699KB
下载 相关 举报
离散数学课件-第2章-3.ppt_第1页
第1页 / 共54页
离散数学课件-第2章-3.ppt_第2页
第2页 / 共54页
离散数学课件-第2章-3.ppt_第3页
第3页 / 共54页
离散数学课件-第2章-3.ppt_第4页
第4页 / 共54页
离散数学课件-第2章-3.ppt_第5页
第5页 / 共54页
点击查看更多>>
资源描述

1、2019/4/19,1,1,离散数学 Discrete Mathematics,汪荣贵 教授 合肥工业大学软件学院专用课件 2010.03,2019/4/19,2,第二章 算法基础,2.1 Algorithms 算法 2.2 Complexity of Algorithms 算法的复杂性 2.3 The Integers and Division 整数和除法 2.4 Integers and Algorithm 整数和算法 2.5 Applications of Number Theory数论的应用 2.6 Matrices 矩阵 2.7 Recursion 递归,学习内容,2019/4/19

2、,4,Number theory(数论)is the branch of mathematics involving the integers and their properties. (数学中涉及整数及其性质的分支)In this section, we will discuss Divisibility 可除性 Greatest common divisor and least common multiple 最大公约数和最小公倍数 Modular arithmetic 模运算 Applications of Congruences 同余应用,整数和除法,2019/4/19,5,除 法

3、定义1 如果a和b是整数,a0,若有整数c使b=ac,就说a整除b。在a整除b时,a是b的一个因子,b是a的倍数。符号ab表示a整除b。当a不能整除b时写成a b,除 法,2019/4/19,6,可被整数d整除的整数,例1 判断是否有3|7,3|12例2 令n和d为正整数。不超过n的正整数中有多少个能为d整除.,2019/4/19,7,Example 1Let n and d be positive integers. How many positive integers not exceeding n are divisible by d?(不超过n的正整数中有多少能被d整除),Soluti

4、on:,The positive integers divisible by d are all the integers of the form dk, where k is a positive integer.能被d整除的正整数都是dk的形的,其中k是正整数,Hence ,the number of positive integers divisible by d that do not exceed n equals the number of integers k with 0dkn, or with 0k n/d.因为不超过n的正整数中能被d整除的整数的个数等于能使0dkn或0k

5、n/d的整数k的个数,Therefore, there are positive integers not exceeding n that are divisible by d.,2019/4/19,8,定理1 令a,b,c 为整数。有:1)若ab和ac,则a(b+c);2)若ab,那么对所有整数c都有abc;3)若ab,bc,则ac。,整除的基本性质,2019/4/19,9, Theorem 1 Let a, b, and c be integers. Then,Some basic properties of divisibility of integers: (整数整除性的某些基本性质

6、),整除的基本性质,2019/4/19,10,素 数 大于1的每个正整数都至少能被两个整数整除,因为正整数可以被1和它自己整除。恰有两个不同的正整数因子的整数称为素数 定义2 大于1的正整数p称为素数,如果p仅有的正因子是1和p。大于1又不是素数的正整数称为合数,素 数,2019/4/19,11,定理2 算术基本定理 每个正整数都可以唯一地表示为素数的乘积,其中素数因子从小到大依次出现。(乘积可以有0个、1个或多个素因子),素 数,2019/4/19,12,Primes (素数), Definition 2 A positive integer p greater than 1 is call

7、ed prime if the only positive factors of p are 1 and p. A positive integer that is greater than 1 and is not prime is called composite(大于1的正整数p称为素数,如果p仅有的正因子是1和p。大于1又不是素数的正整数称为合数)., Theorem 2 THE FUNDAMENTAL THEOREM OF ARITHMETIC (算术基本定理) Every positive integer(n1) can be written uniquely as the pro

8、duct of primes, where the prime factors are written in order of increasing size. ( 每个大于1的正整数都可以唯一地写为两个或多个素数 的乘积,其中素数因子以非递减序出现),2019/4/19,13,例 100,641,999和1024的素因子如解如下: 100=2255=2252 641=641 999=33337=3337 1024=2222222222=210,素 数,2019/4/19,14,定理3(证明是否是素数)如果n是合数,那么n必有一个小于或等于 的素因子如果整数不能被小于或者等于其平方根个的素数整

9、除,那么该数就是一个素数。,素 数,2019/4/19,15,证明 如果n是合数, 它有一个因子a, 使 1an, n=ab,其中a,b都是大于1的整数.,素 数,2019/4/19,16,Problem:,Proof: If n is composite, it must has a factor a with 1an. Hence n=ab.,We see that 1n.,Hence , n has a positive divisor not exceeding .,This divisor is either prime or, by the fundamental Theorem

10、of Arithmetic, has a prime divisor.,In either case, n has a prime divisor less than or equal to .,2019/4/19,17,例:证明101是素数不超过 的仅有的素数是2,3,5,和7.因为101不能被2,3,5和7整除,所以101是素数,素 数,2019/4/19,18,Problem:,How to find the prime factorization of a positive integer? 怎样找出一个整数的素因子?,If no prime factor is found, then

11、 n is prime, otherwise, if a prime factor p is found, continue by factoring n/p. Note that n/p has no prime factors less than p. 如果n无素因子,那么n为素数。如果找到素因子p,那么再对n/p继续这样做。注意n/p没有小于p的素因子。,Begin by dividing n by successive primes, starting with the smallest prime 2 to the largest prime not exceeding .从最小素数

12、2开始到不超过 的素数去除n。,2019/4/19,19,2.4 The Integers and Division,Example 3Find the prime factorization of 7007. 求7007的素因子分解,Solution:要求7007的素因子分解,从2开始用一个个素数除7007. 2,3,5除不尽7007,但7能除尽7007,7007/7=1001. 下一步从7开始用一个个素数除1001.我们立刻发现7还能 除尽1001,1001/7=143. 从7开始,再用一个个素 数除143.虽然7不能整除143,但11可以,143/11=13. 由于13为素数。因此700

13、7的素因子分解是7*7*11*13.,2019/4/19,20,除法算法 定理4 除法算法令a为整数,d为正整数,那么有唯一的整数q和r,其中0rd,使得a=dq+r。 定义3 在上述除法算法给出的等式中,d为除数,a称为被除数,q称为商,r称为余数。,除法算法,2019/4/19,21,The Division Algorithm除法算法, Theorem 4 Let a be an integer and d a positive integer. Then there are unique integers q and r, with 0rd such thata = dq + r. 令

14、a为整数,d为正整数,那么唯一的整数q和r, 其中0rd ,使得a = dq + r.,Note: d is the divisor 除数a is the dividend 被除数q is the quotient 商r is the remainder 余数 (为正整数),Example 4 What are the quotient and remainder when 11 is divided by 3? -11除以3时商和余数是什么?,Solution: 11 = 3 (4) + 1Quotient = 4 and Remainder = 1,2019/4/19,22,Greates

15、t common divisor and least common multiple 最大公约数和最小公倍数, Definition 4 Let a and b be integers, not both zero. The largest integer d such that da and db is called the greatest common divisor of a and b .令a和b是不全为0的两个整数。能使d|a和d|b的最大整数d称为a和b的最大公约数Notation: gcd(a, b) Definition 5 The integers a and b are

16、relatively prime (互素的)if their greatest common divisor is 1.如果整数a和b的最大公约数是1,就说它们是互素的。 Definition 6 The integers a1,a2,an are pairwise relatively prime( 两两互素) if gcd(ai, aj)=1 whenever 1ij n.整数a1,a2,an 是两两互素的,如果只要1ij n,就有gcd(ai, aj)=1 。,2019/4/19,23,Problem: How to find gcd(a,b) ?如何求最大公约数,gcd(a,b) ca

17、n be computed using the prime factorizations of a and b.求整数a、b的最大公约数的方法是利用这两个整数的素因子分解a p1a1 p2a2 pnanb p1b1 p2b2 pnbngcd(a,b) = p1min(a1,b1) p2min(a2,b2) pnmin(an,bn),Example 5 Find gcd(120,500).,Solution: 120 = 23 3 5 = 23 31 51500 = 22 53 = 22 30 53gcd(120,500) = 2min(3,2) 3min(1,0) 5min(1,3)= 22

18、30 51 = 20,2019/4/19,24, Definition 7 The least common multiple of the positive integer a and b is the smallest integer that is divisible by both a and b. 正整数a、b的最小公倍数是能被a和b整除的最小正整数。a和b的最小公倍数用lcm(a, b)表示。Notation: lcm(a, b),Problem: How to find lcm(a,b) ?,lcm(a,b) can be computed using the prime fac

19、torizations of a and b.最小公倍数用lcm(a, b)可以通过这两个整数的素因子分解计算得到。a p1a1 p2a2 pnanb p1b1 p2b2 pnbnlcm(a,b) = p1max(a1,b1) p2max(a2,b2) pnmax(an,bn),2019/4/19,25,能整除两个整数的最大整数称为这两个整数的最大公约数 定义4 令a和b是不全为0的两个整数。能使da和db的最大整数d称为a和b的最大公约数。a和b的最大公约数用gcd(a,b)表示,最大公约数和最小公倍数,2019/4/19,26,定义5 如果整数a和b的最大公约数是1,就说他们是互素的 定义

20、6 整数a1 ,a2,an称为两两互素,如果只要1ijn,就有gcd(ai,aj)=1 定义7 正整数a和b的最小公约数是能被a和b整除的最小正整数。a和b的最小公倍数用lcm(a,b)表示 定理5 令a和b为正整数,则ab=gcd(a,b)lcm(a,b),2019/4/19,27,模运算 定义8 令a为整数,m为正整数。用a mod m表示a被m除的余数例 17 mod 5 = 2 例 -133 mod 9 = 2 例 2001 mod 101 = 82,同余算术,2019/4/19,28,Modular arithmetic (模运算), Definition 8 Let a be an

21、 integer and m be a positive integer, we denote by a mod m the remainder when a is divided by m.,Note: If a = qm + r and 0 r m, then a mod m = r For example, 133 mod 9 = 2 since 133 = 9(-15) + 2 2004 mod 101 = 85 since 2004 = 10119 + 85,2019/4/19,29,定义9 若a和b为整数而m为正整数,如果m整除a-b,就说a与模m同余,用ab(mod m)表示。如

22、果a和b不是模m同余的,就写成a b(mod m)例 判断17是否和5模6同余,24是否和14模6同余 解 由于6整除17-5=12,所以17 5(mod 6)24-14=10不能被6整数,所以24 14(mod 6),同余算术,2019/4/19,30,2.4 The Integers and Division, Definition 9 If a and b are integers and m is a positive integer, then a is congruent to b modulo m (a与b关于模m同余)if m divides a-b.若a和b为整数而m为正整数

23、,如果m整除a-b,就说a模m同余b。,Note:,a b (mod m) if (a mod m)=(b mod m), Theorem 6 Let m be a positive integer.a b (mod m) iif there is an integer ksuch that a = b + km., Theorem 7 Let m be a positive integer.If a b (mod m) and c d (mod m),then a + c b + d (mod m)ac bd (mod m),Notation: ab(mod m),2019/4/19,31,

24、定理6 令m为正整数。整数a和b模m同余的充分必要条件是存在整数k,使a=b+km 证明若a b(mod m)m |(a-b)有整数k使得a-b=km,所以 a=km+b若存在整数k,使得km=a-bM整除a-b, 所以 a b(mod m),模运算,2019/4/19,32,定理7 令m为正整数,若ab(mod m), cd(mod m),那么a+c b+d(mod m)及ac=bd(mod m)。 证明 ab(mod m) b=a+smcd(mod m) d=c+tmb+d=(a+sm)+(c+tm)=(a+c)+(s+t)m bd= =(a+sm)*(c+tm)=ac+m(at+cs+s

25、tm) 因此 a+c=b+d(mod m) 及 ac=bd(mod m),模运算,2019/4/19,33,例 由于72(mod 5)和11 1(mod 5),从定理7知18=7+11 3(mod 5)且77=7 11 2(mod 5),模运算,2019/4/19,34,例 若n|m,m为大于1的正整数, a b(mod m), 其中a,b为整数. 求证a b(mod n),证明:令m=tn。 由于a b(mod m) 必有整数s使a=b+sm 因此a=b+(st)n, 所以a b(mod)n,2019/4/19,35,例 若a,b,k,m为整数,k1,m 2且a b(mod m),求证ak

26、bk(mod m),证明:由于 a b(mod m) 必有整数s使a=b+sm,所以a-b=sm 于是k1时 ak bk =(a-b)(ak-1+ak-2b+abk-2+bk-1)也是m的倍数 于是ak bk(mod m),2019/4/19,36,Hash function 散列函数Pseudorandom Numbers 伪随机数Cryptology (密码学),同余应用,2019/4/19,37,伪随机数,计算机模拟常需要选取随机选择的数目。有不同的方法可以产生具有随机性质的数,由于用系统的方法产生的数不可能真正是随机的,就称为伪随机数。,同余应用,2019/4/19,38,最常用的产生

27、伪随机数的过程称为线性同余法。我们选择4个数:模数m,乘数a,增量c和种数x0使2am,0cm,0x0m。我们生产一个伪随机数序列xn使得对所有n,0xnm。生产的办法是逐次同余: xn+1=(axn + c)mod m,2019/4/19,39,例如选m=9,a=7,c=4,x0=3 x1=7x0+4=7*3+4=25 mod 9 = 7 x2=7x1+4=7*7+4=53 mod 9 = 8 x3=7x2+4=7*8+4=60 mod 9 = 6 x4=7x3+4=7*6+4=46 mod 9 = 1 x5=7x4+4=7*1+4=11 mod 9 = 2 x6=7x5+4=7*2+4=1

28、8 mod 9 = 0 x7=7x6+4=7*0+4=4 mod 9 = 4 x8=7x7+4=7*4+4=32 mod 9 = 5 x9=7x8+4=7*5+4=39 mod 9 = 3由于 x9=x0,而且每一项都只依赖于前面一项,所以产生的序列如下:3,7,8,6,1,2,0,4,5,3,7,8,6,1,2,0,4,5,3,,2019/4/19,40,大部分计算机的确使用线性同余生成器的伪随机数。常使用的线性同余生成器的增量c=0.这样的生成器称为纯乘式生成器。例如以231-1为模,以75=16807为乘数的纯乘式生成器就广为采用。可以证明以这些值来计算,会产生231-2个伪随机数,然后

29、开始重复.,2019/4/19,41,现实社会中,充满了各种各样的信息,例如,军事情报,商业秘密,金融消息,计算机文件,私人通信等等。在很多情况下,人们希望在秘密的情况下保存或传送信息,这就导致了对信息加密的研究。,密码学,2019/4/19,42,对于那些一目了然的信息,我们称为“明文”。 当我们要把某个信息传送给某些人(称之为“合法接收人”)时,是先把明文进行“加密”处理,这种经过加密处理的明文,我们称为“密文”。 密文不是随便甚麽人都可以看懂的。只有合法接收人,他们掌握了一定的方法,才能把它“翻译”成加密处理之前的明文。,2019/4/19,43,总的来说,关于信息加密的研究主要是两个方

30、面: 第一,研究把明文翻译成密文的方法,这个方法要尽可能的简单易行; 第二,研究这种加密方法的保密性(安全性),即,除合法接收人外,其他人从密文了解到明文内容(全部或部分)的可能性。,2019/4/19,44,把明文翻译成密文的过程,称为加密过程,或加密;所用的方法(或公式),称为加密方法(或加密公式)。 把密文翻译成明文的过程,称为解密过程,或解密;所用的方法(或公式),称为解密方法(或解密公式)。,2019/4/19,45,为了能将数论用于明文的加密,首先需要建立明文与正整数的对应关系。一个文件总是由文字和其他符号(标点符号,数字,特殊记号,等等)组成的。假设所使用的字母和符号共有N个,如

31、果把这些符号和N个正整数0,1,2,N 1建立一一对应的关系,那么,文字、符号、句子和文件就都和正整数建立了一一对应的关系。,2019/4/19,46,例如,假设使26个拉丁字母a,b,c,y,z与数字00,01,02,24,25建立了下表所示的一一对应关系:,与“woyaolai”(我要来)对应的数字就是 2214240014110008。,2019/4/19,47,凯撒密码 把每个字母在字母表中往下移动3位 获得保密信息(字母表的后3个字母移为最前3个) 字母B移到E,字母X移到A 最早的密码,密码学,2019/4/19,48,用数学来表达凯撒的加密过程 按照字母在字母表中的位置用0到25

32、的数表示字母。用0表示A,用10表示K,用25表示Z。 凯撒加密方法可以用函数f表示,对每个非负整数p,p25,函数值f(p)是0,1,2,25中的一个数,使f(p)= (p+3) mod 26 在加密信息中,由p代表的字母用(p+3)mod26 代表的字母代替,密码学,2019/4/19,49,凯撒解码 每个字母要在字母表上向上移3位,最前3个字母移到最后3位f-1(p)=(p-3)mod 26 从加密信息恢复成原信息的过程称为解码,密码学,2019/4/19,50,凯撒加密明文与密文的一一对应关系,2019/4/19,51,例 从信息“MEET YOU IN THE PARK”用凯撒密码获

33、得的加密信息是什么?解 首先用数代替信息中的字母,得 12 4 4 19 24 14 20 8 13 19 7 4 15 0 17 10 再用f(p)=(p+3)mod 26代替p,得 15 7 7 22 1 17 23 11 16 22 10 7 18 3 20 13 翻译成加密信息“PHHW BRXLQ WHK SDUN”,密码学,2019/4/19,52,凯撒密码推广不是把字母移动3位,而是移动k位,于是f(p)=(p+k)mod 26 称为移位密码 解码 f-1(p)=(p-k)mod 26 改进 f(p)=(ap+b)mod 26 a和b为整数,而且需保证f为双射,密码学,2019/4/19,53,例 若用f(p)=(7p+3)mod 26加密用什么字母取代字母K? 解 10 代表 Kf(10)=(710+3)mod 26=21因为21代表V,在加密信息中用V代表字母K,本节内容到此结束,谢谢大家!,

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 中等教育 > 职业教育

本站链接:文库   一言   我酷   合作


客服QQ:2549714901微博号:道客多多官方知乎号:道客多多

经营许可证编号: 粤ICP备2021046453号世界地图

道客多多©版权所有2020-2025营业执照举报