Knowledge (XXG)

Lehmer's GCD algorithm

Source 📝

736: 558: 65:
observed that the quotients 1, 2, and 3 comprise 67.7% of all quotients.) Those small quotients can be identified from only a few leading digits. Thus the algorithm starts by splitting off those leading digits and computing the sequence of quotients as long as it is correct.
339: 547: 268: 1365: 731:{\displaystyle \textstyle {\begin{bmatrix}0&1\\1&-w\end{bmatrix}}\cdot {\begin{bmatrix}A&B&x\\C&D&y\end{bmatrix}}={\begin{bmatrix}C&D&y\\A-wC&B-wD&x-wy\end{bmatrix}}} 1369: 877: 910: 799:(again simultaneously). This applies the steps of the euclidean algorithm that were performed on the leading digits in compressed form to the long integers 276: 487: 208: 1234: 870: 1102: 1425: 1044: 863: 973: 1150: 948: 1059: 1097: 1034: 978: 941: 1239: 1130: 1049: 1039: 834: 915: 1067: 37:. It is mainly used for big integers that have a representation as a string of digits relative to some chosen numeral system 1320: 1315: 1244: 1145: 1282: 434:
be the (not computed) quotient from the current long division in the chain of long divisions of the euclidean algorithm.
1196: 1361: 1351: 1310: 1086: 1080: 1054: 925: 1346: 1249: 1122: 968: 920: 1264: 1155: 27: 1375: 1325: 1305: 1026: 1001: 930: 1385: 1380: 1272: 1254: 1229: 1191: 935: 846: 197: 23: 1390: 1356: 1277: 1181: 1140: 1135: 1112: 1016: 106: 34: 1221: 1168: 1165: 1006: 905: 962: 955: 1341: 1297: 1011: 988: 1186: 1176: 1075: 271: 850: 1206: 1107: 1092: 996: 897: 61:
from each step of the division part of the standard algorithm are small. (For example,
334:{\displaystyle \textstyle {\begin{bmatrix}1&0&x\\0&1&y\end{bmatrix}},} 1419: 1201: 886: 542:{\displaystyle \textstyle {\begin{bmatrix}A&B&x\\C&D&y\end{bmatrix}}} 263:{\displaystyle \textstyle {\begin{bmatrix}A&B&x\\C&D&y\end{bmatrix}}} 1211: 829: 62: 855: 889: 30: 58: 742:
according to the matrix formulation of the extended euclidean algorithm.
94: 38: 345:
and perform the euclidean algorithm simultaneously on the pairs (
859: 120:
differ in the length of digits, perform a division so that
764:; perform a normal step of the euclidean algorithm with 1406:
indicate that algorithm is for numbers of special forms
659: 610: 568: 562: 497: 491: 377:), until the quotients differ. That is, iterate as an 286: 280: 218: 212: 561: 490: 279: 211: 1334: 1296: 1263: 1220: 1164: 1121: 1025: 987: 896: 730: 541: 457:, then break out of the inner iteration. Else set 333: 262: 69:Say we want to obtain the GCD of the two integers 871: 8: 157:be the leading (most significant) digit in 33:, an improvement on the simpler but slower 878: 864: 856: 128:are equal in length, with length equal to 654: 605: 563: 560: 492: 489: 281: 278: 213: 210: 105:= 2), use some other method, such as the 822: 751:≠ 0, go to the start of the inner loop. 93:contains only one digit (in the chosen 811:≠ 0 go to the start of the outer loop. 16:Fast greatest common divisor algorithm 7: 14: 1087:Special number field sieve (SNFS) 1081:General number field sieve (GNFS) 837:vol 2 "Seminumerical algorithms" 835:The Art of Computer Programming 57:Lehmer noted that most of the 1: 772:, and restart the outer loop. 1045:Lenstra elliptic curve (ECM) 1426:Number theoretic algorithms 1442: 1352:Exponentiation by squaring 1035:Continued fraction (CFRAC) 839:, chapter 4.5.3 Theorem E. 478:Replace the current matrix 391:of the long divisions of ( 1399: 430:) respectively. Also let 553:with the matrix product 1265:Greatest common divisor 760:= 0, we have reached a 109:, to obtain the result. 1376:Modular exponentiation 732: 543: 384:Compute the quotients 335: 264: 20:Lehmer's GCD algorithm 1103:Shanks's square forms 1027:Integer factorization 1002:Sieve of Eratosthenes 733: 544: 336: 265: 177:the leading digit in 138:Iterate until one of 1381:Montgomery reduction 1255:Function field sieve 1230:Baby-step giant-step 1076:Quadratic sieve (QS) 559: 488: 277: 209: 196:Initialize a 2 by 3 24:Derrick Henry Lehmer 1391:Trachtenberg system 1357:Integer square root 1298:Modular square root 1017:Wheel factorization 969:Quadratic Frobenius 949:Lucas–Lehmer–Riesel 107:Euclidean algorithm 35:Euclidean algorithm 1283:Extended Euclidean 1222:Discrete logarithm 1151:SchĂśnhage–Strassen 1007:Sieve of Pritchard 851:Lehmer's Algorithm 728: 727: 721: 645: 596: 539: 538: 532: 331: 330: 321: 260: 259: 253: 1413: 1412: 1012:Sieve of Sundaram 1433: 1362:Integer relation 1335:Other algorithms 1240:Pollard kangaroo 1131:Ancient Egyptian 989:Prime-generating 974:Solovay–Strassen 887:Number-theoretic 880: 873: 866: 857: 840: 827: 737: 735: 734: 729: 726: 725: 650: 649: 601: 600: 548: 546: 545: 540: 537: 536: 340: 338: 337: 332: 326: 325: 269: 267: 266: 261: 258: 257: 1441: 1440: 1436: 1435: 1434: 1432: 1431: 1430: 1416: 1415: 1414: 1409: 1395: 1330: 1292: 1259: 1216: 1160: 1117: 1021: 983: 956:Proth's theorem 898:Primality tests 892: 884: 847:Kapil Paranjape 843: 828: 824: 820: 720: 719: 705: 691: 676: 675: 670: 665: 655: 644: 643: 638: 633: 627: 626: 621: 616: 606: 595: 594: 586: 580: 579: 574: 564: 557: 556: 531: 530: 525: 520: 514: 513: 508: 503: 493: 486: 485: 474: 467: 456: 449: 413: 390: 320: 319: 314: 309: 303: 302: 297: 292: 282: 275: 274: 272:identity matrix 270:to an extended 252: 251: 246: 241: 235: 234: 229: 224: 214: 207: 206: 55: 17: 12: 11: 5: 1439: 1437: 1429: 1428: 1418: 1417: 1411: 1410: 1408: 1407: 1400: 1397: 1396: 1394: 1393: 1388: 1383: 1378: 1373: 1359: 1354: 1349: 1344: 1338: 1336: 1332: 1331: 1329: 1328: 1323: 1318: 1316:Tonelli–Shanks 1313: 1308: 1302: 1300: 1294: 1293: 1291: 1290: 1285: 1280: 1275: 1269: 1267: 1261: 1260: 1258: 1257: 1252: 1250:Index calculus 1247: 1245:Pohlig–Hellman 1242: 1237: 1232: 1226: 1224: 1218: 1217: 1215: 1214: 1209: 1204: 1199: 1197:Newton-Raphson 1194: 1189: 1184: 1179: 1173: 1171: 1162: 1161: 1159: 1158: 1153: 1148: 1143: 1138: 1133: 1127: 1125: 1123:Multiplication 1119: 1118: 1116: 1115: 1110: 1108:Trial division 1105: 1100: 1095: 1093:Rational sieve 1090: 1083: 1078: 1073: 1065: 1057: 1052: 1047: 1042: 1037: 1031: 1029: 1023: 1022: 1020: 1019: 1014: 1009: 1004: 999: 997:Sieve of Atkin 993: 991: 985: 984: 982: 981: 976: 971: 966: 959: 952: 945: 938: 933: 928: 923: 921:Elliptic curve 918: 913: 908: 902: 900: 894: 893: 885: 883: 882: 875: 868: 860: 854: 853: 842: 841: 821: 819: 816: 815: 814: 813: 812: 773: 754: 753: 752: 744: 743: 740: 739: 738: 724: 718: 715: 712: 709: 706: 704: 701: 698: 695: 692: 690: 687: 684: 681: 678: 677: 674: 671: 669: 666: 664: 661: 660: 658: 653: 648: 642: 639: 637: 634: 632: 629: 628: 625: 622: 620: 617: 615: 612: 611: 609: 604: 599: 593: 590: 587: 585: 582: 581: 578: 575: 573: 570: 569: 567: 551: 550: 549: 535: 529: 526: 524: 521: 519: 516: 515: 512: 509: 507: 504: 502: 499: 498: 496: 480: 479: 476: 472: 465: 454: 447: 438: 437: 436: 435: 411: 388: 343: 342: 341: 329: 324: 318: 315: 313: 310: 308: 305: 304: 301: 298: 296: 293: 291: 288: 287: 285: 256: 250: 247: 245: 242: 240: 237: 236: 233: 230: 228: 225: 223: 220: 219: 217: 201: 200: 194: 133: 110: 54: 51: 22:, named after 15: 13: 10: 9: 6: 4: 3: 2: 1438: 1427: 1424: 1423: 1421: 1405: 1402: 1401: 1398: 1392: 1389: 1387: 1384: 1382: 1379: 1377: 1374: 1371: 1367: 1363: 1360: 1358: 1355: 1353: 1350: 1348: 1345: 1343: 1340: 1339: 1337: 1333: 1327: 1324: 1322: 1319: 1317: 1314: 1312: 1311:Pocklington's 1309: 1307: 1304: 1303: 1301: 1299: 1295: 1289: 1286: 1284: 1281: 1279: 1276: 1274: 1271: 1270: 1268: 1266: 1262: 1256: 1253: 1251: 1248: 1246: 1243: 1241: 1238: 1236: 1233: 1231: 1228: 1227: 1225: 1223: 1219: 1213: 1210: 1208: 1205: 1203: 1200: 1198: 1195: 1193: 1190: 1188: 1185: 1183: 1180: 1178: 1175: 1174: 1172: 1170: 1167: 1163: 1157: 1154: 1152: 1149: 1147: 1144: 1142: 1139: 1137: 1134: 1132: 1129: 1128: 1126: 1124: 1120: 1114: 1111: 1109: 1106: 1104: 1101: 1099: 1096: 1094: 1091: 1089: 1088: 1084: 1082: 1079: 1077: 1074: 1072: 1070: 1066: 1064: 1062: 1058: 1056: 1055:Pollard's rho 1053: 1051: 1048: 1046: 1043: 1041: 1038: 1036: 1033: 1032: 1030: 1028: 1024: 1018: 1015: 1013: 1010: 1008: 1005: 1003: 1000: 998: 995: 994: 992: 990: 986: 980: 977: 975: 972: 970: 967: 965: 964: 960: 958: 957: 953: 951: 950: 946: 944: 943: 939: 937: 934: 932: 929: 927: 924: 922: 919: 917: 914: 912: 909: 907: 904: 903: 901: 899: 895: 891: 888: 881: 876: 874: 869: 867: 862: 861: 858: 852: 848: 845: 844: 838: 836: 831: 826: 823: 817: 810: 806: 802: 798: 794: 790: 786: 782: 778: 774: 771: 767: 763: 759: 755: 750: 746: 745: 741: 722: 716: 713: 710: 707: 702: 699: 696: 693: 688: 685: 682: 679: 672: 667: 662: 656: 651: 646: 640: 635: 630: 623: 618: 613: 607: 602: 597: 591: 588: 583: 576: 571: 565: 555: 554: 552: 533: 527: 522: 517: 510: 505: 500: 494: 484: 483: 482: 481: 477: 471: 464: 460: 453: 446: 442: 441: 440: 439: 433: 429: 425: 421: 417: 410: 406: 402: 398: 394: 387: 383: 382: 380: 376: 372: 368: 364: 360: 356: 352: 348: 344: 327: 322: 316: 311: 306: 299: 294: 289: 283: 273: 254: 248: 243: 238: 231: 226: 221: 215: 205: 204: 203: 202: 199: 195: 192: 188: 184: 180: 176: 172: 168: 164: 160: 156: 152: 148: 147: 145: 141: 137: 134: 131: 127: 123: 119: 115: 111: 108: 104: 100: 96: 92: 88: 87: 86: 84: 80: 76: 72: 67: 64: 60: 52: 50: 48: 44: 40: 36: 32: 29: 25: 21: 1403: 1287: 1085: 1068: 1060: 979:Miller–Rabin 961: 954: 947: 942:Lucas–Lehmer 940: 833: 825: 808: 804: 800: 796: 792: 788: 784: 780: 776: 769: 765: 761: 757: 748: 469: 462: 458: 451: 444: 431: 427: 423: 419: 415: 408: 404: 400: 396: 392: 385: 378: 374: 370: 366: 362: 358: 354: 350: 346: 190: 186: 182: 178: 174: 170: 166: 162: 158: 154: 153:by one. Let 150: 143: 139: 135: 129: 125: 121: 117: 113: 102: 98: 90: 82: 78: 74: 70: 68: 56: 46: 42: 26:, is a fast 19: 18: 1235:Pollard rho 1192:Goldschmidt 926:Pocklington 916:Baillie–PSW 136:Outer loop: 1347:Cornacchia 1342:Chakravala 890:algorithms 818:References 379:inner loop 101:= 1000 or 45:= 1000 or 1321:Berlekamp 1278:Euclidean 1166:Euclidean 1146:Toom–Cook 1141:Karatsuba 711:− 697:− 683:− 603:⋅ 589:− 149:Decrease 146:is zero: 59:quotients 53:Algorithm 31:algorithm 1420:Category 1288:Lehmer's 1182:Chunking 1169:division 1098:Fermat's 762:deadlock 450:≠ 81:≥ 1404:Italics 1326:Kunerth 1306:Cipolla 1187:Fourier 1156:FĂźrer's 1050:Euler's 1040:Dixon's 963:PĂŠpin's 361:) and ( 1386:Schoof 1273:Binary 1177:Binary 1113:Shor's 931:Fermat 422:) by ( 407:) and 399:) by ( 198:matrix 97:, say 77:. Let 47:β 43:β 41:, say 1207:Short 936:Lucas 830:Knuth 807:. If 63:Knuth 49:= 2. 1202:Long 1136:Long 803:and 787:and 775:Set 768:and 468:(or 414:of ( 189:div 173:and 169:div 124:and 116:and 95:base 73:and 39:base 1366:LLL 1212:SRT 1071:+ 1 1063:− 1 911:APR 906:AKS 791:to 779:to 756:If 747:If 461:to 443:If 142:or 112:If 89:If 28:GCD 1422:: 1370:KZ 1368:; 849:, 832:, 797:Db 795:+ 793:Ca 785:bB 783:+ 781:aA 475:). 426:+ 418:+ 403:+ 395:+ 381:: 373:+ 369:, 365:+ 357:+ 353:, 349:+ 185:= 181:, 165:= 161:, 85:. 1372:) 1364:( 1069:p 1061:p 879:e 872:t 865:v 809:b 805:b 801:a 789:b 777:a 770:b 766:a 758:B 749:B 723:] 717:y 714:w 708:x 703:D 700:w 694:B 689:C 686:w 680:A 673:y 668:D 663:C 657:[ 652:= 647:] 641:y 636:D 631:C 624:x 619:B 614:A 608:[ 598:] 592:w 584:1 577:1 572:0 566:[ 534:] 528:y 523:D 518:C 511:x 506:B 501:A 495:[ 473:2 470:w 466:1 463:w 459:w 455:2 452:w 448:1 445:w 432:w 428:D 424:y 420:B 416:x 412:2 409:w 405:C 401:y 397:A 393:x 389:1 386:w 375:D 371:y 367:B 363:x 359:C 355:y 351:A 347:x 328:, 323:] 317:y 312:1 307:0 300:x 295:0 290:1 284:[ 255:] 249:y 244:D 239:C 232:x 227:B 222:A 216:[ 193:. 191:β 187:b 183:y 179:b 175:y 171:β 167:a 163:x 159:a 155:x 151:m 144:b 140:a 132:. 130:m 126:b 122:a 118:b 114:a 103:β 99:β 91:b 83:b 79:a 75:b 71:a

Index

Derrick Henry Lehmer
GCD
algorithm
Euclidean algorithm
base
quotients
Knuth
base
Euclidean algorithm
matrix
identity matrix
Knuth
The Art of Computer Programming
Kapil Paranjape
Lehmer's Algorithm
v
t
e
Number-theoretic
algorithms
Primality tests
AKS
APR
Baillie–PSW
Elliptic curve
Pocklington
Fermat
Lucas
Lucas–Lehmer
Lucas–Lehmer–Riesel

Text is available under the Creative Commons Attribution-ShareAlike License. Additional terms may apply.

↑