Example #1
0
def testFactorial() -> bool:
    sample = [
        [0, 1],
        [1, 1],
        [2, 2],
        [3, 6],
        [4, 24],
        [5, 120],
        [6, 720],
        [7, 5040],
        [8, 40320],
        [9, 362880],
        [10, 3_628_800],
        [11, 39_916_800],
        [12, 479_001_600],
    ]

    for i, _ in enumerate(sample):
        if NumberTheory.factorial(sample[i][0]) != sample[i][1]:
            return False

    return True
Example #2
0
def testIsPrime() -> bool:
    sample = [
        [0, 1],
        [1, 1],
        [2, 2],
        [3, 2],
        [4, 4],
        [5, 2],
        [6, 4],
        [7, 2],
        [8, 4],
        [9, 4],
        [10, 4],
        [11, 2],
        [12, 4],
        [13, 2],
        [14, 4],
        [15, 4],
        [16, 4],
        [17, 2],
        [18, 4],
        [19, 2],
        [20, 4],
        [21, 4],
        [22, 4],
        [23, 2],
        [24, 4],
        [25, 4],
        [26, 4],
        [27, 4],
        [28, 4],
        [29, 2],
        [30, 4],
        [31, 2],
        [32, 4],
        [33, 4],
        [34, 4],
        [35, 4],
        [36, 4],
        [37, 2],
        [38, 4],
        [39, 4],
        [40, 4],
        [41, 2],
        [42, 4],
        [43, 2],
        [44, 4],
        [45, 4],
        [46, 4],
        [47, 2],
        [48, 4],
        [49, 4],
        [50, 4],
        [51, 4],
        [52, 4],
        [53, 2],
        [54, 4],
        [55, 4],
        [56, 4],
        [57, 4],
        [58, 4],
        [59, 2],
        [60, 4],
        [61, 2],
        [62, 4],
        [63, 4],
        [64, 4],
        [65, 4],
        [66, 4],
        [67, 2],
        [68, 4],
        [69, 4],
        [70, 4],
        [71, 2],
        [72, 4],
        [73, 2],
        [74, 4],
        [75, 4],
        [76, 4],
        [77, 4],
        [78, 4],
        [79, 2],
        [80, 4],
        [81, 4],
        [82, 4],
        [83, 2],
        [84, 4],
        [85, 4],
        [86, 4],
        [87, 4],
        [88, 4],
        [89, 2],
        [90, 4],
        [91, 4],
        [92, 4],
        [93, 4],
        [94, 4],
        [95, 4],
        [96, 4],
        [97, 2],
        [98, 4],
        [99, 4],
        [100, 4],
        [101, 2],
        [102, 4],
        [103, 2],
        [104, 4],
        [105, 4],
        [106, 4],
        [107, 2],
        [108, 4],
        [109, 2],
        [110, 4],
        [111, 4],
        [112, 4],
        [113, 2],
        [114, 4],
        [115, 4],
        [116, 4],
        [117, 4],
        [118, 4],
        [119, 4],
        [120, 4],
        [121, 4],
        [122, 4],
        [123, 4],
        [124, 4],
        [125, 4],
        [126, 4],
        [127, 2],
        [170, 4],
        [271, 2],
        [357, 4],
        [225, 4],
        [440, 4],
        [235, 4],
        [274, 4],
        [383, 2],
        [313, 2],
        [434, 4],
        [222, 4],
        [137, 2],
        [155, 4],
        [465, 4],
        [249, 4],
        [141, 4],
        [5307, 4],
        [6374, 4],
        [951, 4],
        [7236, 4],
        [2027, 2],
        [2382, 4],
        [2251, 2],
        [757, 2],
        [6678, 4],
        [3206, 4],
        [6257, 2],
        [615, 4],
        [1677, 4],
        [2086, 4],
        [4158, 4],
        [4723, 2],
        [7755, 4],
        [1583, 2],
        [6547, 2],
        [4219, 2],
        [660, 4],
        [7698, 4],
        [3121, 2],
        [3881, 2],
        [2541, 4],
        [4696, 4],
        [4091, 2],
        [5222, 4],
        [4021, 2],
        [5839, 2],
        [6048, 4],
        [5521, 2],
        [47908, 4],
        [35060, 4],
        [47361, 4],
        [48859, 2],
        [56067, 4],
        [70451, 2],
        [9735, 4],
        [19763, 2],
        [97943, 2],
        [9933, 4],
        [61651, 2],
        [11407, 4],
        [8774, 4],
        [48383, 2],
        [51001, 2],
        [73029, 4],
        [27690, 4],
        [30466, 4],
        [71479, 2],
        [84701, 2],
        [28643, 2],
        [57075, 4],
        [99745, 4],
        [100921, 4],
        [40496, 4],
        [9798, 4],
        [41603, 2],
        [46912, 4],
        [49852, 4],
        [55871, 2],
        [10993, 2],
        [79657, 2],
        [609680, 4],
        [180540, 4],
        [147672, 4],
        [819031, 2],
        [149623, 2],
        [1_056_048, 4],
        [483389, 2],
        [452831, 2],
        [415109, 2],
        [185021, 2],
        [715823, 2],
        [744081, 4],
        [1_276_157, 2],
        [192978, 4],
        [631537, 2],
        [554226, 4],
        [653111, 2],
        [607346, 4],
        [452539, 2],
        [815939, 2],
        [247199, 4],
        [1_245_953, 2],
        [974803, 2],
        [185813, 2],
        [1_261_831, 2],
        [443227, 2],
        [1_057_294, 4],
        [427241, 2],
        [627391, 2],
        [1_019_663, 2],
        [629142, 4],
        [164503, 2],
        [6_006_421, 2],
        [9_499_199, 2],
        [12_598_247, 2],
        [13_919_909, 2],
        [8_975_950, 4],
        [6_655_578, 4],
        [2_388_697, 2],
        [14_018_237, 4],
        [7_871_261, 2],
        [1_678_013, 2],
        [2_654_027, 2],
        [10_142_801, 2],
        [2_291_487, 4],
        [3_893_849, 2],
        [1_308_913, 4],
        [14_162_880, 4],
    ]

    for i, _ in enumerate(sample):
        if sample[i][1] == 1:
            if NumberTheory.isPrime(sample[i][0]):
                return False
        elif sample[i][1] == 2:
            if not NumberTheory.isPrime(sample[i][0]):
                return False
        else:
            if NumberTheory.isPrime(sample[i][0]):
                return False

    return True
Example #3
0
def testIsOdd() -> bool:
    sample = [
        [0, 0],
        [1, 1],
        [-1, 1],
        [60, 0],
        [62, 0],
        [42, 0],
        [-87, 1],
        [-98, 0],
        [-56, 0],
        [41, 1],
        [14, 0],
        [20, 0],
        [-63, 1],
        [-81, 1],
        [-39, 1],
        [33, 1],
        [-32, 0],
        [-50, 0],
        [-1471, 1],
        [4046, 0],
        [5019, 1],
        [4521, 1],
        [-8744, 0],
        [4787, 1],
        [4973, 1],
        [-1184, 0],
        [-4437, 1],
        [-5871, 1],
        [-4298, 0],
        [-2027, 1],
        [-2796, 0],
        [-2209, 1],
        [-6094, 0],
        [3257, 1],
        [-4732, 0],
        [7495, 1],
        [-3916, 0],
        [1469, 1],
        [6164, 0],
        [-7545, 1],
        [-7763, 1],
        [7523, 1],
        [-8076, 0],
        [-3778, 0],
        [-1648, 0],
        [4220, 0],
        [-8551, 1],
        [9692, 0],
        [5394, 0],
        [2472, 0],
        [4056, 0],
        [5769, 1],
        [-2322, 0],
        [503, 1],
        [-8721, 1],
        [-6344, 0],
        [-4335, 1],
        [1677, 1],
        [-1703, 1],
        [-4086, 0],
        [7076, 0],
        [-7165, 1],
        [7636, 0],
        [-8043, 1],
        [-3753, 1],
        [4007, 1],
        [-261, 1],
        [-6538, 0],
        [9766, 0],
        [-7563, 1],
        [-7944, 0],
        [8922, 0],
        [-5759, 1],
        [-8791, 1],
        [-2211, 1],
        [3493, 1],
        [5573, 1],
        [-2645, 1],
        [-603656, 0],
        [807727, 1],
        [-69847, 1],
        [-843676, 0],
        [-830961, 1],
        [-608772, 0],
        [931043, 1],
        [855512, 0],
        [358482, 0],
        [-98919, 1],
        [215211, 1],
        [-933334, 0],
        [-613634, 0],
        [-95643, 1],
        [53934, 0],
        [161818, 0],
        [67_041_621, 1],
        [99_662_694, 0],
        [-94_392_019, 1],
        [-20_543_495, 1],
        [-27_591_794, 0],
        [-8_314_396, 0],
        [97_455_764, 0],
        [59_367_920, 0],
        [26_856_309, 1],
        [64_178_815, 1],
        [-11_480_741, 1],
        [45_428_276, 0],
        [46_193_175, 1],
        [-31_079_636, 0],
        [63_115_980, 0],
        [42_559_270, 0],
        [-1_645_871_504, 0],
        [-1_233_918_598, 0],
        [722_012_346, 0],
        [-1_525_999_934, 0],
        [-365_543_955, 1],
        [2_008_798_151, 1],
        [-1_300_713_468, 0],
        [1_425_587_979, 1],
        [1_324_445_673, 1],
        [2_136_612_365, 1],
        [-995_371_213, 1],
        [-2_048_365_905, 1],
        [2_096_138_065, 1],
        [-768_738_192, 0],
        [-846_034_014, 0],
        [411_817_058, 0],
        [2_147_483_647, 1],
        [-2_147_483_648, 0],
    ]

    for i, _ in enumerate(sample):
        if sample[i][1] == 0:
            if NumberTheory.isOdd(sample[i][0]):
                return False
        else:
            if not NumberTheory.isOdd(sample[i][0]):
                return False

    return True
Example #4
0
def testIsCoprime() -> bool:
    sample = [
        [0, 1, 1],
        [1, 0, 1],
        [1, 1, 1],
        [-1, -1, 1],
        [15, -45, 0],
        [-7, 51, 1],
        [-3, 75, 0],
        [-84, -32, 0],
        [-21, -71, 1],
        [89, -11, 1],
        [-40, -9, 1],
        [92, 26, 0],
        [14, -95, 1],
        [5, -99, 1],
        [-45, -57, 0],
        [59, -97, 1],
        [-16, 37, 1],
        [97, 49, 1],
        [5998, -3871, 1],
        [-2152, -2909, 1],
        [8823, 629, 0],
        [7589, -7035, 1],
        [-8669, 6398, 1],
        [1059, 3522, 0],
        [9892, -2990, 0],
        [-1819, 4740, 1],
        [7900, -7244, 0],
        [8072, -1226, 0],
        [-6875, 5777, 1],
        [-828, 8859, 0],
        [-3929, 1143, 1],
        [-5397, 1880, 1],
        [-9397, -4343, 1],
        [2389, -4026, 1],
        [-6838, -7802, 0],
        [-6118, 7944, 0],
        [1408, -8483, 1],
        [-507, 3510, 0],
        [5030, -4818, 0],
        [2563, -1867, 1],
        [3317, -4585, 1],
        [-2448, -2215, 1],
        [-1982, -3811, 1],
        [645, 7907, 1],
        [5812, 1657, 1],
        [3944, -5997, 1],
        [-2410, -6522, 0],
        [4565, 9055, 0],
        [8478, 1099, 0],
        [6444, -7298, 0],
        [7606, -7006, 0],
        [2491, -2017, 1],
        [7151, -9724, 1],
        [2958, -5697, 0],
        [5134, -7701, 0],
        [-3544, 9042, 0],
        [8826, -4548, 0],
        [6794, -5322, 0],
        [-6906, 7502, 0],
        [172, 8480, 0],
        [8244, 4622, 0],
        [-7315, 5253, 1],
        [7011, 4285, 1],
        [-3132, -4999, 1],
        [-7332, -655, 1],
        [9661, -1750, 1],
        [7560, -3128, 0],
        [1334, 6234, 0],
        [8075, 6450, 0],
        [3283, 8980, 1],
        [3364, 8482, 0],
        [4909, 8302, 1],
        [9332, -2523, 1],
        [-8515, 5209, 1],
        [-1624, 7640, 0],
        [-6463, 2562, 1],
        [7912, 5868, 0],
        [-4825, -2173, 1],
        [28876, 30106, 0],
        [-929840, 887043, 1],
        [684923, -588038, 1],
        [-291411, -299801, 1],
        [-905447, -402122, 1],
        [830872, -223425, 1],
        [831033, -753398, 1],
        [-575558, 711716, 0],
        [-312296, 515492, 0],
        [595308, 963205, 0],
        [-770718, -388434, 0],
        [353889, 330806, 1],
        [-174566, 613742, 0],
        [-884075, 26687, 1],
        [390743, 204874, 1],
        [930615, 86524, 1],
        [-84_945_524, 15_427_487, 1],
        [76_038_602, -89_688_904, 0],
        [50_294_214, -65_802_481, 1],
        [83_436_075, 44_248_708, 1],
        [54_031_677, 92_370_464, 1],
        [-6_019_575, -1_302_029, 1],
        [86_952_873, -75_470_243, 1],
        [-53_215_372, 28_947_490, 0],
        [-37_109_442, 75_623_090, 0],
        [-11_656_183, 16_147_085, 1],
        [86_439_843, -12_134_914, 1],
        [-52_977_427, 48_349_835, 1],
        [16_234_161, 26_103_566, 1],
        [73_756_826, -6_586_797, 1],
        [6_836_355, 11_529_043, 1],
        [29_864_126, -80_782_077, 1],
        [1_646_787_325, 1_961_513_442, 1],
        [-1_755_035_190, -1_801_169_490, 0],
        [-1_509_018_194, 1_829_751_775, 1],
        [-720_160_017, -1_425_309_680, 1],
        [1_216_287_038, 1_821_933_798, 0],
        [-1_925_479_607, -1_842_455_762, 1],
        [-795_996_486, -1_859_155_567, 1],
        [-367_280_505, 321_267_794, 1],
        [829_304_526, -1_575_808_585, 1],
        [1_457_917_042, 1_083_382_210, 0],
        [-377_130_535, 1_526_538_188, 1],
        [-1_109_347_700, -1_819_333_109, 1],
        [-1_740_794_578, 278_770_346, 0],
        [448_156_480, -1_008_775_746, 0],
        [442_691_160, 1_680_572_092, 0],
        [1_241_208_470, -647_438_045, 0],
        [2_147_483_647, -561_158_902, 1],
        [761_395_308, -2_147_483_647, 1],
    ]

    for i, _ in enumerate(sample):
        if sample[i][2] == 0:
            if NumberTheory.isCoprime(sample[i][0], sample[i][1]):
                return False
        else:
            if not NumberTheory.isCoprime(sample[i][0], sample[i][1]):
                return False

    return True
Example #5
0
def testLCM() -> bool:
    sample = [
        [1, 1, 1],
        [-1, -1, 1],
        [-85, -8, 680],
        [33, -2, 66],
        [8, 32, 32],
        [8, 89, 712],
        [16, 78, 624],
        [-66, -2, 66],
        [-50, -62, 1550],
        [12, -25, 300],
        [-74, -25, 1850],
        [4, 24, 24],
        [90, 29, 2610],
        [-62, -85, 5270],
        [-9, -50, 450],
        [90, -59, 5310],
        [-8732, -1743, 15_219_876],
        [-8329, 8430, 70_213_470],
        [3300, -1326, 729300],
        [-5969, -523, 3_121_787],
        [-7044, -8745, 20_533_260],
        [-4683, 2491, 11_665_353],
        [9729, 4329, 4_679_649],
        [-871, 3189, 2_777_619],
        [-1158, -3122, 1_807_638],
        [9912, -9910, 49_113_960],
        [4924, 5842, 14_383_004],
        [3980, -6455, 5_138_180],
        [5420, -1507, 8_167_940],
        [-1090, 7747, 8_444_230],
        [-8008, 7290, 29_189_160],
        [-2260, -6189, 13_987_140],
        [-962, 9376, 4_509_856],
        [-351, 8756, 3_073_356],
        [-171, 8401, 1_436_571],
        [-3110, -7937, 24_684_070],
        [6362, 1928, 6_132_968],
        [-8230, 964, 3_966_860],
        [-5791, 6186, 35_823_126],
        [-4204, 9556, 10_043_356],
        [-3338, 6848, 11_429_312],
        [-760, 8766, 3_331_080],
        [-1958, 4928, 438592],
        [-3830, -107, 409810],
        [-7809, 9720, 25_301_160],
        [7665, 209, 1_601_985],
        [-6060, 4881, 9_859_620],
        [2346, -9979, 1_377_102],
        [7125, -5604, 13_309_500],
        [9862, 3015, 29_733_930],
        [-1148, 8092, 331772],
        [8627, 3929, 33_895_483],
        [-5320, 8927, 47_491_640],
        [-2301, -8803, 20_255_703],
        [6395, -8793, 56_231_235],
        [6278, -2847, 244842],
        [1623, 3406, 5_527_938],
        [-3974, 1259, 5_003_266],
        [-4014, -3066, 2_051_154],
        [7546, -3833, 28_923_818],
        [4058, -4338, 8_801_802],
        [5066, 7450, 126650],
        [-9458, -5234, 24_751_586],
        [4142, 5319, 22_031_298],
        [4119, -9963, 13_679_199],
        [813, 1892, 1_538_196],
        [4375, 9055, 7_923_125],
        [388, -4329, 1_679_652],
        [3927, 5720, 2_042_040],
        [5099, -5563, 28_365_737],
        [-4174, 4772, 9_959_164],
        [-8829, 6842, 60_408_018],
        [9834, 8283, 2_468_334],
        [-6028, -2949, 17_776_572],
        [2627, -2463, 6_470_301],
        [9431, -5198, 49_022_338],
        [4553, 6198, 28_219_494],
        [1368, -8772, 1_000_008],
        [-43336, -36185, 1_568_113_160],
        [33606, -19136, 321_542_208],
        [-23381, 31250, 730_656_250],
        [-22377, -22397, 501_177_669],
        [-22766, -10042, 114_308_086],
        [-37379, -13431, 502_037_349],
        [-23248, -18591, 432_203_568],
        [-34910, 37688, 657_844_040],
        [-29156, 26259, 765_607_404],
        [33346, 19239, 641_543_694],
        [-31634, 13587, 429_811_158],
        [22300, 14536, 81_038_200],
        [-25315, 26148, 661_936_620],
        [-21579, -43116, 310_133_388],
        [-25141, 37870, 952_089_670],
        [23741, 10471, 248_592_011],
        [26852, -41498, 557_152_148],
        [26627, -21629, 575_915_383],
        [-13538, -16865, 228_318_370],
        [25331, 31258, 791_796_398],
        [33885, 13483, 456_871_455],
        [-43671, -16383, 238_487_331],
        [-29483, 26616, 784_719_528],
        [15792, -11008, 10_864_896],
        [23749, 40466, 961_027_034],
        [-37432, -42397, 1_587_004_504],
        [-46035, -24237, 123_972_255],
        [-38120, 10830, 41_283_960],
        [-11808, -10396, 30_688_992],
        [-15667, -15508, 242_963_836],
        [-15336, -35057, 537_634_152],
        [31050, -13757, 427_154_850],
        [42602, -20701, 881_904_002],
        [-20505, 18475, 75_765_975],
        [35445, 12527, 444_019_515],
        [-20600, -23702, 244_130_600],
        [21432, 15715, 336_803_880],
        [-24635, 45838, 86_863_010],
        [20616, 41256, 35_438_904],
        [-40536, 29009, 1_175_908_824],
        [-29015, -40786, 1_183_405_790],
        [17092, -30650, 261_934_900],
        [-44577, 31261, 1_393_521_597],
        [-35517, 13916, 494_254_572],
        [-22680, 39616, 112_311_360],
        [33207, -33473, 1_111_537_911],
        [30250, -28845, 174_512_250],
        [45203, -23693, 1_070_994_679],
        [46340, 46341, 2_147_441_940],
        [-46340, -46341, 2_147_441_940],
    ]

    for i, _ in enumerate(sample):
        if NumberTheory.lcm(sample[i][0], sample[i][1]) != sample[i][2]:
            return False

    return True
Example #6
0
def testGCD() -> bool:
    sample = [
        [0, 1, 1],
        [1, 0, 1],
        [1, 1, 1],
        [-1, -1, 1],
        [-25, 72, 1],
        [-16, -48, 16],
        [-56, -54, 2],
        [29, -60, 1],
        [40, -58, 2],
        [-61, 97, 1],
        [-81, -99, 9],
        [-46, 59, 1],
        [59, -55, 1],
        [-36, 14, 2],
        [-42, 19, 1],
        [-22, 44, 22],
        [-14, 84, 14],
        [-99, 6, 3],
        [-7864, 2672, 8],
        [8228, 2179, 1],
        [-1622, -4471, 1],
        [8293, -4881, 1],
        [9936, 3701, 1],
        [3828, -9134, 2],
        [-9055, 934, 1],
        [-9427, 2762, 1],
        [-9960, 6904, 8],
        [-2912, 1062, 2],
        [7678, 8016, 2],
        [-3919, 5143, 1],
        [-5080, -9523, 1],
        [8388, -952, 4],
        [8996, 2305, 1],
        [-6576, 3950, 2],
        [887, -6760, 1],
        [8148, -8500, 4],
        [5170, -3469, 1],
        [-7312, 2220, 4],
        [-9841, 742, 1],
        [3525, 3121, 1],
        [-8986, 4466, 2],
        [5192, -2843, 1],
        [2196, 4569, 3],
        [8895, 644, 1],
        [7633, -1624, 1],
        [9405, -2678, 1],
        [-4444, -4640, 4],
        [2729, 6047, 1],
        [-5458, 5100, 2],
        [7727, -2644, 1],
        [9825, -3348, 3],
        [-7670, 1745, 5],
        [-9678, -2111, 1],
        [4804, -2588, 4],
        [4541, 3146, 1],
        [8691, -8489, 1],
        [-9432, -9286, 2],
        [7370, 2247, 1],
        [-6928, 7638, 2],
        [-2610, 4698, 522],
        [999, -349, 1],
        [-1954, 5542, 2],
        [7277, 7843, 1],
        [-815, 3671, 1],
        [-4961, -4919, 1],
        [-3079, -2410, 1],
        [-1594, 2267, 1],
        [5889, -1103, 1],
        [-2327, 2864, 179],
        [-9761, 2090, 1],
        [5879, 976, 1],
        [-5212, -6742, 2],
        [-1803, 3566, 1],
        [8078, -9213, 1],
        [6391, 8997, 1],
        [-7333, -2185, 1],
        [9552, 6474, 6],
        [3775, -7699, 1],
        [-975165, 693821, 1],
        [-283946, -681458, 2],
        [393833, -268145, 1],
        [93577, -938355, 517],
        [201821, -279303, 1],
        [288085, -62375, 5],
        [98342, 460581, 1],
        [875349, -88237, 1],
        [-101284, -152553, 1],
        [-711500, -228037, 1],
        [413727, 811772, 1],
        [-286175, -99810, 5],
        [959681, 662872, 1],
        [-541593, -211585, 1],
        [935328, -878838, 6],
        [544408, -614262, 2],
        [56_791_606, 10_091_252, 2],
        [76_184_637, 55_338_231, 3],
        [87_827_010, -2_054_112, 6],
        [-51_336_665, 47_647_691, 1],
        [26_786_890, 3_898_842, 2],
        [70_964_172, 27_242_363, 1],
        [50_572_364, 24_895_820, 4],
        [-10_321_594, 90_477_203, 1],
        [-90_182_979, -79_448_469, 3],
        [73_849_322, -30_438_170, 2],
        [-30_825_301, -45_682_165, 1],
        [-29_366_775, 65_070_021, 3],
        [19_996_288, -66_270_963, 1],
        [-3_388_067, 94_646_426, 1],
        [28_009_079, 59_009_075, 1],
        [-35_854_012, -13_548_532, 4],
        [-1_341_557_375, -1_706_521_640, 5],
        [-1_703_927_494, 617_390_757, 1],
        [-1_926_730_755, 1_188_983_365, 5],
        [533_277_970, -542_110_746, 2],
        [1_508_525_543, 869_090_704, 1],
        [1_234_248_685, 1_606_411_314, 1],
        [-1_698_647_648, -1_816_407_074, 2],
        [1_149_345_284, 1_170_749_266, 2],
        [-711_810_797, -908_541_229, 1],
        [424_509_982, 712_101_099, 1],
        [1_996_000_380, -457_046_405, 5],
        [943_706_285, -419_105_596, 1],
        [-249_463_342, -2_050_490_722, 2],
        [-1_981_012_181, -1_584_006_152, 1],
        [1_483_217_656, 1_658_473_101, 1],
        [-1_069_835_847, 1_308_503_268, 3],
        [2_147_483_647, -1_884_119_046, 1],
        [645_159_694, -2_147_483_647, 1],
    ]

    for i, _ in enumerate(sample):
        if NumberTheory.gcd(sample[i][0], sample[i][1]) != sample[i][2]:
            return False

    return True
Example #7
0
def testFibonacci() -> bool:
    sample = [
        [-31, 1346269],
        [-30, -832040],
        [-29, 514229],
        [-28, -317811],
        [-27, 196418],
        [-26, -121393],
        [-25, 75025],
        [-24, -46368],
        [-23, 28657],
        [-22, -17711],
        [-21, 10946],
        [-20, -6765],
        [-19, 4181],
        [-18, -2584],
        [-17, 1597],
        [-16, -987],
        [-15, 610],
        [-14, -377],
        [-13, 233],
        [-12, -144],
        [-11, 89],
        [-10, -55],
        [-9, 34],
        [-8, -21],
        [-7, 13],
        [-6, -8],
        [-5, 5],
        [-4, -3],
        [-3, 2],
        [-2, -1],
        [-1, 1],
        [0, 0],
        [1, 1],
        [2, 1],
        [3, 2],
        [4, 3],
        [5, 5],
        [6, 8],
        [7, 13],
        [8, 21],
        [9, 34],
        [10, 55],
        [11, 89],
        [12, 144],
        [13, 233],
        [14, 377],
        [15, 610],
        [16, 987],
        [17, 1597],
        [18, 2584],
        [19, 4181],
        [20, 6765],
        [21, 10946],
        [22, 17711],
        [23, 28657],
        [24, 46368],
        [25, 75025],
        [26, 121393],
        [27, 196418],
        [28, 317811],
        [29, 514229],
        [30, 832040],
        [31, 1346269],
    ]

    for i, _ in enumerate(sample):
        if NumberTheory.fibonacci(sample[i][0]) != sample[i][1]:
            return False

    return True
Example #8
0
def testSieveOfPrimes() -> bool:
    sample = [
        [0, 0],
        [1, 0],
        [180, 41],
        [26, 9],
        [350, 70],
        [521, 98],
        [307, 63],
        [163, 38],
        [181, 42],
        [372, 73],
        [421, 82],
        [241, 53],
        [229, 50],
        [169, 39],
        [442, 85],
        [445, 86],
        [338, 68],
        [306, 62],
        [56, 16],
        [270, 57],
        [499, 95],
        [173, 40],
        [18, 7],
        [43, 14],
        [218, 47],
        [122, 30],
        [265, 56],
        [467, 91],
        [381, 75],
        [11, 5],
        [409, 80],
        [233, 51],
        [1119, 187],
        [6976, 896],
        [4355, 594],
        [7757, 984],
        [3467, 486],
        [5824, 764],
        [7724, 980],
        [1470, 232],
        [7894, 997],
        [6788, 873],
        [7873, 994],
        [6874, 885],
        [3554, 497],
        [4137, 569],
        [7878, 995],
        [3390, 477],
        [2141, 323],
        [4642, 626],
        [2718, 396],
        [7126, 912],
        [1022, 172],
        [5651, 743],
        [4822, 649],
        [2022, 306],
        [6449, 837],
        [2153, 325],
        [1323, 216],
        [6960, 893],
        [2837, 412],
        [4212, 576],
        [2179, 327],
        [1033, 174],
        [33023, 3540],
        [65798, 6572],
        [39761, 4179],
        [12379, 1478],
        [25339, 2794],
        [50093, 5143],
        [98641, 9471],
        [84959, 8272],
        [90697, 8778],
        [20898, 2350],
        [63079, 6326],
        [18369, 2104],
        [23459, 2611],
        [55337, 5620],
        [55057, 5596],
        [94463, 9111],
        [22769, 2544],
        [22501, 2516],
        [68369, 6799],
        [65315, 6524],
        [72893, 7206],
        [44969, 4672],
        [69511, 6902],
        [24371, 2705],
        [32579, 3497],
        [26017, 2862],
        [84309, 8217],
        [100043, 9595],
        [86861, 8440],
        [79355, 7776],
        [14445, 1693],
        [95418, 9197],
        [1209025, 93544],
        [526733, 43583],
        [832339, 66339],
        [350593, 30017],
        [616581, 50358],
        [787123, 62995],
        [474923, 39612],
        [320448, 27647],
        [617049, 50394],
        [232333, 20622],
        [651727, 52944],
        [524873, 43427],
        [1008852, 79161],
        [187573, 16970],
        [432235, 36339],
        [714479, 57629],
        [669287, 54254],
        [633133, 51574],
        [964012, 75920],
        [663127, 53800],
        [1257461, 96995],
        [172171, 15681],
        [1112392, 86634],
        [912533, 72211],
        [409529, 34574],
        [691575, 55914],
        [742768, 59730],
        [479430, 39964],
        [108289, 10303],
        [1228187, 94920],
        [709431, 57257],
        [1294061, 99610],
    ]

    arr = None

    for i, _ in enumerate(sample):
        arr = NumberTheory.sieveOfPrimes(sample[i][0])

        if len(arr) != sample[i][1]:
            return False

        for v in arr:
            if not Primality.isPrime(v):
                return False

    return True