Instantly share code, notes, and snippets.

# tkmharris/a345209.py

Last active June 11, 2021 22:14
Show Gist options
• Save tkmharris/8bbeaf4f2d34f88dc5cef678a81cb6b9 to your computer and use it in GitHub Desktop.
Code for OEIS sequence A345209
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 """ Function to calculate terms of OEIS sequence A345209. """ from sympy import primefactors def a345209(n): """ Calculate OEIS entry A345209(n) (Number of Petrie polygons on regular triangular map corresponding to the principal congruence subgroup Γ(n) of the mmodular group) n: int, >=1 return: int """ # degenerate cases if n == 1 or n == 2: return 1 # calculate index of Γ(n) in Γ (a001766(n), n>=3) # given by formula ((n^3)/2)*Product_{p | n, p prime} (1-1/p^2), for n>=3. index = n**3 for p in primefactors(n): index *= (p**2 - 1) index //= p**2 index //= 2 # calculate pisano semiperiod (a301759(n), n>=2) # period of the Fibonacci numbers modulo n up to a sign sigma = 1 a, b = 1, 1 while (a,b) != (0,1) and (a,b) != (0, n - 1): a, b = b, (a + b) % n sigma += 1 # a(n) = index / sigma # https://doi.org/10.26493/1855-3974.864.e9b, Corollary 7.3 return index // sigma """ # uncomment this block to print 50 sample values print(",".join([str(a345209(n)) for n in range(1, 51)])) """
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 """ Script to generate b-file. """ from a345209 import a345209 def b345209(n=1000): """ Generate b-file for OEIS entry A345209. n: int, >=1 return: None """ bfile = "b345209.txt" with open(bfile, 'w') as f: f.writelines([f"{i} {a345209(i)}\n" for i in range(1, n+1)]) b345209()
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
 1 1 2 1 3 3 4 4 5 6 6 6 7 21 8 16 9 27 10 12 11 66 12 24 13 78 14 42 15 36 16 64 17 136 18 162 19 190 20 48 21 252 22 132 23 253 24 192 25 150 26 156 27 243 28 168 29 870 30 72 31 496 32 256 33 396 34 816 35 252 36 648 37 666 38 1140 39 468 40 384 41 1722 42 504 43 903 44 1056 45 324 46 1518 47 3243 48 1536 49 1029 50 300 51 816 52 624 53 1378 54 1458 55 3960 56 1344 57 1140 58 1740 59 1770 60 576 61 3782 62 2976 63 2268 64 1024 65 1872 66 792 67 2211 68 3264 69 3036 70 504 71 2556 72 5184 73 2628 74 1332 75 900 76 9120 77 2772 78 936 79 3160 80 1536 81 2187 82 3444 83 3403 84 4032 85 3264 86 1806 87 5220 88 4224 89 16020 90 1944 91 3276 92 6072 93 2976 94 6486 95 2280 96 6144 97 4656 98 2058 99 3564 100 1200 101 10302 102 4896 103 5253 104 4992 105 6048 106 8268 107 17013 108 5832 109 11990 110 7920 111 3996 112 10752 113 18984 114 6840 115 3036 116 13920 117 4212 118 3540 119 5712 120 4608 121 7986 122 22692 123 41328 124 23808 125 3750 126 13608 127 8001 128 4096 129 21672 130 3744 131 8646 132 6336 133 7980 134 4422 135 2916 136 26112 137 9316 138 18216 139 29190 140 4032 141 38916 142 5112 143 10296 144 41472 145 10440 146 5256 147 12348 148 5328 149 22350 150 1800 151 34428 152 36480 153 22032 154 5544 155 29760 156 7488 157 12246 158 18960 159 8268 160 6144 161 85008 162 13122 163 13203 164 13776 165 47520 166 20418 167 13861 168 32256 169 13182 170 19584 171 30780 172 7224 173 14878 174 10440 175 6300 176 16896 177 10620 178 32040 179 16110 180 15552 181 32942 182 6552 183 22692 184 48576 185 15984 186 17856 187 17952 188 25944 189 20412 190 13680 191 18336 192 24576 193 18528 194 9312 195 11232 196 8232 197 19306 198 21384 199 179100 200 9600 201 53064 202 20604 203 36540 204 39168 205 103320 206 10506 207 81972 208 19968 209 50160 210 12096 211 111830 212 33072 213 15336 214 102078 215 10836 216 46656 217 20832 218 71940 219 15768 220 63360 221 42432 222 7992 223 24753 224 86016 225 8100 226 37968 227 25651 228 54720 229 52670 230 18216 231 66528 232 55680 233 243252 234 25272 235 38916 236 28320 237 18960 238 34272 239 28680 240 36864 241 58322 242 15972 243 19683 244 90768 245 12348 246 82656 247 29640 248 95232 249 81672 250 7500 251 31626 252 108864 253 33396 254 16002 255 19584 256 16384 257 32896 258 43344 259 27972 260 14976 261 46980 262 17292 263 103359 264 50688 265 33072 266 47880 267 96120 268 17688 269 72630 270 17496 271 36856 272 104448 273 78624 274 55896 275 99000 276 145728 277 38226 278 58380 279 80352 280 32256 281 396210 282 77832 283 39903 284 40896 285 27360 286 20592 287 144648 288 165888 289 39304 290 20880 291 27936 292 21024 293 42778 294 24696 295 21240 296 42624 297 32076 298 44700 299 39468 300 14400 301 75852 302 68856 303 61812 304 145920 305 453840 306 132192 307 328797 308 44352 309 63036 310 178560 311 48516 312 59904 313 48828 314 24492 315 54432 316 151680 317 50086 318 49608 319 229680 320 24576 321 408312 322 510048 323 465120 324 52488 325 46800 326 26406 327 71940 328 110208 329 544824 330 95040 331 164838 332 81672 333 35964 334 83166 335 26532 336 258048 337 56616 338 26364 339 113904 340 78336 341 654720 342 184680 343 50421 344 57792 345 72864 346 89268 347 180093 348 83520 349 122150 350 12600 351 37908 352 67584 353 186384 354 21240 355 153360 356 128160 357 137088 358 32220 359 64620 360 124416 361 68590 362 197652 363 47916 364 52416 365 63072 366 136152 367 67161 368 388608 369 371952 370 31968 371 57876 372 142848 373 69378 374 107712 375 22500 376 207552 377 950040 378 122472 379 72010 380 109440 381 96012 382 36672 383 73153 384 98304 385 332640 386 37056 387 195048 388 37248 389 151710 390 22464 391 206448 392 65856 393 51876 394 115836 395 37920 396 171072 397 78606 398 358200 399 191520 400 38400 401 322404 402 106128 403 77376 404 164832 405 26244 406 73080 407 87912 408 313344 409 167690 410 206640 411 55896 412 42024 413 74340 414 491832 415 40836 416 79872 417 175140 418 300960 419 87990 420 96768 421 888310 422 670980 423 350244 424 264576 425 81600 426 30672 427 158844 428 408312 429 123552 430 21672 431 93096 432 373248 433 93528 434 124992 435 125280 436 287760 437 288420 438 31536 439 96580 440 506880 441 111132 442 254592 443 97903 444 63936 445 384480 446 49506 447 134100 448 344064 449 202050 450 48600 451 1136520 452 151872 453 206568 454 153906 455 78624 456 437760 457 104196 458 316020 459 594864 460 145728 461 1064910 462 133056 463 106953 464 222720 465 357120 466 486504 467 108811 468 202176 469 185724 470 77832 471 73476 472 113280 473 119196 474 113760 475 57000 476 274176 477 223236 478 57360 479 114960 480 147456 481 207792 482 349932 483 1020096 484 127776 485 111744 486 118098 487 118341 488 726144 489 316872 490 24696 491 120786 492 330624 493 236640 494 177840 495 427680 496 380928 497 107352 498 490032 499 124750 500 30000 501 166332 502 63252 503 126253 504 870912 505 618120 506 200376 507 79092 508 64008 509 259590 510 117504 511 110376 512 65536 513 831060 514 197376 515 63036 516 173376 517 428076 518 55944 519 89268 520 119808 521 2719620 522 281880 523 136503 524 138336 525 151200 526 206718 527 404736 528 405504 529 133837 530 198432 531 95580 532 383040 533 268632 534 192240 535 204156 536 141504 537 96660 538 145260 539 135828 540 139968 541 879666 542 221136 543 197652 544 417792 545 287760 546 157248 547 149331 548 223584 549 612684 550 198000 551 661200 552 1165824 553 132720 554 76452 555 95904 556 467040 557 1393614 558 482112 559 140868 560 258048 561 215424 562 792420 563 474609 564 622656 565 455616 566 79806 567 183708 568 163584 569 324330 570 164160 571 163306 572 164736 573 110016 574 289296 575 75900 576 663552 577 166176 578 235824 579 111168 580 167040 581 285852 582 55872 583 181896 584 168192 585 101088 586 256668 587 171991 588 197568 589 1130880 590 42480 591 115836 592 170496 593 175528 594 192456 595 137088 596 178800 597 1074600 598 236808 599 179700 600 115200 601 361802 602 151704 603 477576 604 550848 605 479160 606 123624 607 183921 608 583680 609 876960 610 2723040 611 505908 612 1057536 613 187578 614 657594 615 2479680 616 354816 617 190036 618 126072 619 575670 620 1428480 621 737748 622 97032 623 672840 624 479232 625 93750 626 97656 627 300960 628 97968 629 362304 630 326592 631 199396 632 606720 633 670980 634 300516 635 96012 636 396864 637 1123668 638 459360 639 138024 640 98304 641 411522 642 2449872 643 206403 644 2040192 645 260064 646 2790720 647 208981 648 419904 649 467280 650 93600 651 499968 652 105624 653 212878 654 431640 655 518760 656 881664 657 141912 658 1089648 659 217470 660 760320 661 1312746 662 329676 663 254592 664 653376 665 191520 666 215784 667 440220 668 332664 669 297036 670 53064 671 2496120 672 2064384 673 226128 674 113232 675 72900 676 105456 677 686478 678 227808 679 195552 680 626688 681 615624 682 3928320 683 232903 684 1477440 685 223584 686 100842 687 316020 688 462336 689 429936 690 437184 691 1195430 692 357072 693 598752 694 360186 695 350280 696 668160 697 468384 698 732900 699 1459512 700 100800 701 492102 702 227448 703 253080 704 270336 705 933984 706 372768 707 432684 708 169920 709 1510170 710 306720 711 511920 712 1025280 713 752928 714 822528 715 1235520 716 257760 717 172080 718 129240 719 258840 720 995328 721 1765008 722 411540 723 699864 724 1581216 725 261000 726 95832 727 263901 728 419328 729 177147 730 126144 731 245616 732 1089216 733 268278 734 134322 735 296352 736 3108864 737 291852 738 2231712 739 273430 740 127872 741 355680 742 347256 743 826959 744 1142784 745 536400 746 138756 747 2205144 748 861696 749 1429092 750 45000 751 282376 752 1660416 753 189756 754 1900080 755 2065680 756 979776 757 286146 758 432060 759 801504 760 875520 761 1159764 762 192024 763 503580 764 293376 765 528768 766 438918 767 276120 768 393216 769 2368520 770 665280 771 197376 772 148224 773 298378 774 1170288 775 744000 776 297984 777 671328 778 303420 779 654360 780 179712 781 3373920 782 1238688 783 422820 784 526848 785 293904 786 103752 787 309291 788 463344 789 1240308 790 227520 791 797328 792 1368576 793 1179984 794 157212 795 198432 796 2865600 797 2220442 798 1149120 799 882096 800 153600 801 865080 802 644808 803 346896 804 424512 805 1020096 806 464256 807 435780 808 659328 809 1310580 810 157464 811 987798 812 584640 813 221136 814 175824 815 158436 816 2506752 817 343140 818 1006140 819 707616 820 1653120 821 674862 822 335376 823 338253 824 336192 825 1188000 826 148680 827 341551 828 3934656 829 2064210 830 245016 831 229356 832 319488 833 279888 834 350280 835 166332 836 2407680 837 723168 838 175980 839 352380 840 774144 841 731670 842 5329860 843 9509040 844 5367840 845 316368 846 2101464 847 335412 848 1058304 849 957672 850 489600 851 336996 852 245376 853 363378 854 953064 855 738720 856 3266496 857 366796 858 247104 859 4063070 860 173376 861 3471552 862 186192 863 371953 864 1492992 865 357072 866 187056 867 235824 868 999936 869 834240 870 250560 871 344916 872 2302080 873 251424 874 1730520 875 157500 876 252288 877 384126 878 579480 879 256668 880 2027520 881 3885210 882 666792 883 389403 884 1018368 885 254880 886 587418 887 392941 888 511488 889 1344168 890 768960 891 288684 892 198024 893 1232340 894 268200 895 193320 896 1376256 897 947232 898 404100 899 1726080 900 388800 901 6746688 902 2273040 903 1820448 904 1214976 905 1976520 906 413136 907 410871 908 615624 909 556308 910 157248 911 5400408 912 3502080 913 449196 914 208392 915 2723040 916 2528160 917 363132 918 3569184 919 3804660 920 1165824 921 7891128 922 2129820 923 2791152 924 1064448 925 399600 926 213906 927 567324 928 890880 929 863970 930 2142720 931 391020 932 1946016 933 291096 934 652866 935 2154240 936 1617408 937 438516 938 371448 939 292968 940 622656 941 886422 942 146952 943 1742664 944 453120 945 489888 946 238392 947 447931 948 910080 949 819936 950 342000 951 300516 952 2193408 953 4082652 954 1339416 955 1100160 956 458880 957 1378080 958 229920 959 391272 960 589824 961 476656 962 415584 963 11024424 964 1399728 965 444672 966 6120576 967 5137671 968 511104 969 5581440 970 223488 971 471906 972 472392 973 1225980 974 236682 975 280800 976 2904576 977 1430328 978 633744 979 2114640 980 197568 981 1942380 982 241572 983 482653 984 2644992 985 463344 986 1419840 987 13075776 988 1422720 989 913836 990 2566080 991 2457680 992 1523712 993 989028 994 214704 995 2149200 996 1960128 997 496506 998 748500 999 323676 1000 240000