SharedHKAGE - Sage Programming.sagewsOpen in CoCalc
Author: Kai Chiu Wu
Views : 458
%md # Reference materials Previous years material can be found in https://matp1061.netlify.com/courses/

Reference materials

Previous years material can be found in

https://matp1061.netlify.com/courses/

%md # Exercise ## Problem 1 Find the $ 1 + 2 + 3 + \cdots + 2019$.

Exercise

Problem 1

Find the 1+2+3++2019 1 + 2 + 3 + \cdots + 2019.

%sage sum([1..2019])
2039190
%md ## Problem 2 Find the rightmost three digits of $2018^{10019}$.

Problem 2

Find the rightmost three digits of 2018100192018^{10019}

2018^10019 % 10^3
632
%md ## Problem 3 Find the first 10 digits of $\sqrt{3}$.

Problem 3

Find the first 10 digits of 3\sqrt{3}.

%sage sqrt(3).n(digits=10)
1.732050808
%md ## Problem 4 Find all divisors of $2500$.

Problem 4

Find all divisors of 25002500.

%sage divisors(2500)
[1, 2, 4, 5, 10, 20, 25, 50, 100, 125, 250, 500, 625, 1250, 2500]
%md ## Problem 5 Find the largest prime factor of $10^{19}+1$

Problem 5

Find the largest prime factor of 1019+110^{19}+1

list(factor(10^19+1))[1][0]
909090909090909091
%md ## Problem 6 Find the sum of square of divisors of $2500$.

Problem 6

Find the sum of square of divisors of 25002500

%sage sum([k^2 for k in divisors(2500)])
8544921
%sage #Construct a list with conditions [k^2 for k in [1..10] if k%2==1]
[1, 9, 25, 49, 81]
%sage # Maximum odd divisor max([k for k in divisors(2500) if k%2==1])
625
# List of greatest odd divisors from 2001 to 4000 [max([k for k in divisors(N) if k%2==1]) for N in [2001..4000]]
[2001, 1001, 2003, 501, 2005, 1003, 2007, 251, 2009, 1005, 2011, 503, 2013, 1007, 2015, 63, 2017, 1009, 2019, 505, 2021, 1011, 2023, 253, 2025, 1013, 2027, 507, 2029, 1015, 2031, 127, 2033, 1017, 2035, 509, 2037, 1019, 2039, 255, 2041, 1021, 2043, 511, 2045, 1023, 2047, 1, 2049, 1025, 2051, 513, 2053, 1027, 2055, 257, 2057, 1029, 2059, 515, 2061, 1031, 2063, 129, 2065, 1033, 2067, 517, 2069, 1035, 2071, 259, 2073, 1037, 2075, 519, 2077, 1039, 2079, 65, 2081, 1041, 2083, 521, 2085, 1043, 2087, 261, 2089, 1045, 2091, 523, 2093, 1047, 2095, 131, 2097, 1049, 2099, 525, 2101, 1051, 2103, 263, 2105, 1053, 2107, 527, 2109, 1055, 2111, 33, 2113, 1057, 2115, 529, 2117, 1059, 2119, 265, 2121, 1061, 2123, 531, 2125, 1063, 2127, 133, 2129, 1065, 2131, 533, 2133, 1067, 2135, 267, 2137, 1069, 2139, 535, 2141, 1071, 2143, 67, 2145, 1073, 2147, 537, 2149, 1075, 2151, 269, 2153, 1077, 2155, 539, 2157, 1079, 2159, 135, 2161, 1081, 2163, 541, 2165, 1083, 2167, 271, 2169, 1085, 2171, 543, 2173, 1087, 2175, 17, 2177, 1089, 2179, 545, 2181, 1091, 2183, 273, 2185, 1093, 2187, 547, 2189, 1095, 2191, 137, 2193, 1097, 2195, 549, 2197, 1099, 2199, 275, 2201, 1101, 2203, 551, 2205, 1103, 2207, 69, 2209, 1105, 2211, 553, 2213, 1107, 2215, 277, 2217, 1109, 2219, 555, 2221, 1111, 2223, 139, 2225, 1113, 2227, 557, 2229, 1115, 2231, 279, 2233, 1117, 2235, 559, 2237, 1119, 2239, 35, 2241, 1121, 2243, 561, 2245, 1123, 2247, 281, 2249, 1125, 2251, 563, 2253, 1127, 2255, 141, 2257, 1129, 2259, 565, 2261, 1131, 2263, 283, 2265, 1133, 2267, 567, 2269, 1135, 2271, 71, 2273, 1137, 2275, 569, 2277, 1139, 2279, 285, 2281, 1141, 2283, 571, 2285, 1143, 2287, 143, 2289, 1145, 2291, 573, 2293, 1147, 2295, 287, 2297, 1149, 2299, 575, 2301, 1151, 2303, 9, 2305, 1153, 2307, 577, 2309, 1155, 2311, 289, 2313, 1157, 2315, 579, 2317, 1159, 2319, 145, 2321, 1161, 2323, 581, 2325, 1163, 2327, 291, 2329, 1165, 2331, 583, 2333, 1167, 2335, 73, 2337, 1169, 2339, 585, 2341, 1171, 2343, 293, 2345, 1173, 2347, 587, 2349, 1175, 2351, 147, 2353, 1177, 2355, 589, 2357, 1179, 2359, 295, 2361, 1181, 2363, 591, 2365, 1183, 2367, 37, 2369, 1185, 2371, 593, 2373, 1187, 2375, 297, 2377, 1189, 2379, 595, 2381, 1191, 2383, 149, 2385, 1193, 2387, 597, 2389, 1195, 2391, 299, 2393, 1197, 2395, 599, 2397, 1199, 2399, 75, 2401, 1201, 2403, 601, 2405, 1203, 2407, 301, 2409, 1205, 2411, 603, 2413, 1207, 2415, 151, 2417, 1209, 2419, 605, 2421, 1211, 2423, 303, 2425, 1213, 2427, 607, 2429, 1215, 2431, 19, 2433, 1217, 2435, 609, 2437, 1219, 2439, 305, 2441, 1221, 2443, 611, 2445, 1223, 2447, 153, 2449, 1225, 2451, 613, 2453, 1227, 2455, 307, 2457, 1229, 2459, 615, 2461, 1231, 2463, 77, 2465, 1233, 2467, 617, 2469, 1235, 2471, 309, 2473, 1237, 2475, 619, 2477, 1239, 2479, 155, 2481, 1241, 2483, 621, 2485, 1243, 2487, 311, 2489, 1245, 2491, 623, 2493, 1247, 2495, 39, 2497, 1249, 2499, 625, 2501, 1251, 2503, 313, 2505, 1253, 2507, 627, 2509, 1255, 2511, 157, 2513, 1257, 2515, 629, 2517, 1259, 2519, 315, 2521, 1261, 2523, 631, 2525, 1263, 2527, 79, 2529, 1265, 2531, 633, 2533, 1267, 2535, 317, 2537, 1269, 2539, 635, 2541, 1271, 2543, 159, 2545, 1273, 2547, 637, 2549, 1275, 2551, 319, 2553, 1277, 2555, 639, 2557, 1279, 2559, 5, 2561, 1281, 2563, 641, 2565, 1283, 2567, 321, 2569, 1285, 2571, 643, 2573, 1287, 2575, 161, 2577, 1289, 2579, 645, 2581, 1291, 2583, 323, 2585, 1293, 2587, 647, 2589, 1295, 2591, 81, 2593, 1297, 2595, 649, 2597, 1299, 2599, 325, 2601, 1301, 2603, 651, 2605, 1303, 2607, 163, 2609, 1305, 2611, 653, 2613, 1307, 2615, 327, 2617, 1309, 2619, 655, 2621, 1311, 2623, 41, 2625, 1313, 2627, 657, 2629, 1315, 2631, 329, 2633, 1317, 2635, 659, 2637, 1319, 2639, 165, 2641, 1321, 2643, 661, 2645, 1323, 2647, 331, 2649, 1325, 2651, 663, 2653, 1327, 2655, 83, 2657, 1329, 2659, 665, 2661, 1331, 2663, 333, 2665, 1333, 2667, 667, 2669, 1335, 2671, 167, 2673, 1337, 2675, 669, 2677, 1339, 2679, 335, 2681, 1341, 2683, 671, 2685, 1343, 2687, 21, 2689, 1345, 2691, 673, 2693, 1347, 2695, 337, 2697, 1349, 2699, 675, 2701, 1351, 2703, 169, 2705, 1353, 2707, 677, 2709, 1355, 2711, 339, 2713, 1357, 2715, 679, 2717, 1359, 2719, 85, 2721, 1361, 2723, 681, 2725, 1363, 2727, 341, 2729, 1365, 2731, 683, 2733, 1367, 2735, 171, 2737, 1369, 2739, 685, 2741, 1371, 2743, 343, 2745, 1373, 2747, 687, 2749, 1375, 2751, 43, 2753, 1377, 2755, 689, 2757, 1379, 2759, 345, 2761, 1381, 2763, 691, 2765, 1383, 2767, 173, 2769, 1385, 2771, 693, 2773, 1387, 2775, 347, 2777, 1389, 2779, 695, 2781, 1391, 2783, 87, 2785, 1393, 2787, 697, 2789, 1395, 2791, 349, 2793, 1397, 2795, 699, 2797, 1399, 2799, 175, 2801, 1401, 2803, 701, 2805, 1403, 2807, 351, 2809, 1405, 2811, 703, 2813, 1407, 2815, 11, 2817, 1409, 2819, 705, 2821, 1411, 2823, 353, 2825, 1413, 2827, 707, 2829, 1415, 2831, 177, 2833, 1417, 2835, 709, 2837, 1419, 2839, 355, 2841, 1421, 2843, 711, 2845, 1423, 2847, 89, 2849, 1425, 2851, 713, 2853, 1427, 2855, 357, 2857, 1429, 2859, 715, 2861, 1431, 2863, 179, 2865, 1433, 2867, 717, 2869, 1435, 2871, 359, 2873, 1437, 2875, 719, 2877, 1439, 2879, 45, 2881, 1441, 2883, 721, 2885, 1443, 2887, 361, 2889, 1445, 2891, 723, 2893, 1447, 2895, 181, 2897, 1449, 2899, 725, 2901, 1451, 2903, 363, 2905, 1453, 2907, 727, 2909, 1455, 2911, 91, 2913, 1457, 2915, 729, 2917, 1459, 2919, 365, 2921, 1461, 2923, 731, 2925, 1463, 2927, 183, 2929, 1465, 2931, 733, 2933, 1467, 2935, 367, 2937, 1469, 2939, 735, 2941, 1471, 2943, 23, 2945, 1473, 2947, 737, 2949, 1475, 2951, 369, 2953, 1477, 2955, 739, 2957, 1479, 2959, 185, 2961, 1481, 2963, 741, 2965, 1483, 2967, 371, 2969, 1485, 2971, 743, 2973, 1487, 2975, 93, 2977, 1489, 2979, 745, 2981, 1491, 2983, 373, 2985, 1493, 2987, 747, 2989, 1495, 2991, 187, 2993, 1497, 2995, 749, 2997, 1499, 2999, 375, 3001, 1501, 3003, 751, 3005, 1503, 3007, 47, 3009, 1505, 3011, 753, 3013, 1507, 3015, 377, 3017, 1509, 3019, 755, 3021, 1511, 3023, 189, 3025, 1513, 3027, 757, 3029, 1515, 3031, 379, 3033, 1517, 3035, 759, 3037, 1519, 3039, 95, 3041, 1521, 3043, 761, 3045, 1523, 3047, 381, 3049, 1525, 3051, 763, 3053, 1527, 3055, 191, 3057, 1529, 3059, 765, 3061, 1531, 3063, 383, 3065, 1533, 3067, 767, 3069, 1535, 3071, 3, 3073, 1537, 3075, 769, 3077, 1539, 3079, 385, 3081, 1541, 3083, 771, 3085, 1543, 3087, 193, 3089, 1545, 3091, 773, 3093, 1547, 3095, 387, 3097, 1549, 3099, 775, 3101, 1551, 3103, 97, 3105, 1553, 3107, 777, 3109, 1555, 3111, 389, 3113, 1557, 3115, 779, 3117, 1559, 3119, 195, 3121, 1561, 3123, 781, 3125, 1563, 3127, 391, 3129, 1565, 3131, 783, 3133, 1567, 3135, 49, 3137, 1569, 3139, 785, 3141, 1571, 3143, 393, 3145, 1573, 3147, 787, 3149, 1575, 3151, 197, 3153, 1577, 3155, 789, 3157, 1579, 3159, 395, 3161, 1581, 3163, 791, 3165, 1583, 3167, 99, 3169, 1585, 3171, 793, 3173, 1587, 3175, 397, 3177, 1589, 3179, 795, 3181, 1591, 3183, 199, 3185, 1593, 3187, 797, 3189, 1595, 3191, 399, 3193, 1597, 3195, 799, 3197, 1599, 3199, 25, 3201, 1601, 3203, 801, 3205, 1603, 3207, 401, 3209, 1605, 3211, 803, 3213, 1607, 3215, 201, 3217, 1609, 3219, 805, 3221, 1611, 3223, 403, 3225, 1613, 3227, 807, 3229, 1615, 3231, 101, 3233, 1617, 3235, 809, 3237, 1619, 3239, 405, 3241, 1621, 3243, 811, 3245, 1623, 3247, 203, 3249, 1625, 3251, 813, 3253, 1627, 3255, 407, 3257, 1629, 3259, 815, 3261, 1631, 3263, 51, 3265, 1633, 3267, 817, 3269, 1635, 3271, 409, 3273, 1637, 3275, 819, 3277, 1639, 3279, 205, 3281, 1641, 3283, 821, 3285, 1643, 3287, 411, 3289, 1645, 3291, 823, 3293, 1647, 3295, 103, 3297, 1649, 3299, 825, 3301, 1651, 3303, 413, 3305, 1653, 3307, 827, 3309, 1655, 3311, 207, 3313, 1657, 3315, 829, 3317, 1659, 3319, 415, 3321, 1661, 3323, 831, 3325, 1663, 3327, 13, 3329, 1665, 3331, 833, 3333, 1667, 3335, 417, 3337, 1669, 3339, 835, 3341, 1671, 3343, 209, 3345, 1673, 3347, 837, 3349, 1675, 3351, 419, 3353, 1677, 3355, 839, 3357, 1679, 3359, 105, 3361, 1681, 3363, 841, 3365, 1683, 3367, 421, 3369, 1685, 3371, 843, 3373, 1687, 3375, 211, 3377, 1689, 3379, 845, 3381, 1691, 3383, 423, 3385, 1693, 3387, 847, 3389, 1695, 3391, 53, 3393, 1697, 3395, 849, 3397, 1699, 3399, 425, 3401, 1701, 3403, 851, 3405, 1703, 3407, 213, 3409, 1705, 3411, 853, 3413, 1707, 3415, 427, 3417, 1709, 3419, 855, 3421, 1711, 3423, 107, 3425, 1713, 3427, 857, 3429, 1715, 3431, 429, 3433, 1717, 3435, 859, 3437, 1719, 3439, 215, 3441, 1721, 3443, 861, 3445, 1723, 3447, 431, 3449, 1725, 3451, 863, 3453, 1727, 3455, 27, 3457, 1729, 3459, 865, 3461, 1731, 3463, 433, 3465, 1733, 3467, 867, 3469, 1735, 3471, 217, 3473, 1737, 3475, 869, 3477, 1739, 3479, 435, 3481, 1741, 3483, 871, 3485, 1743, 3487, 109, 3489, 1745, 3491, 873, 3493, 1747, 3495, 437, 3497, 1749, 3499, 875, 3501, 1751, 3503, 219, 3505, 1753, 3507, 877, 3509, 1755, 3511, 439, 3513, 1757, 3515, 879, 3517, 1759, 3519, 55, 3521, 1761, 3523, 881, 3525, 1763, 3527, 441, 3529, 1765, 3531, 883, 3533, 1767, 3535, 221, 3537, 1769, 3539, 885, 3541, 1771, 3543, 443, 3545, 1773, 3547, 887, 3549, 1775, 3551, 111, 3553, 1777, 3555, 889, 3557, 1779, 3559, 445, 3561, 1781, 3563, 891, 3565, 1783, 3567, 223, 3569, 1785, 3571, 893, 3573, 1787, 3575, 447, 3577, 1789, 3579, 895, 3581, 1791, 3583, 7, 3585, 1793, 3587, 897, 3589, 1795, 3591, 449, 3593, 1797, 3595, 899, 3597, 1799, 3599, 225, 3601, 1801, 3603, 901, 3605, 1803, 3607, 451, 3609, 1805, 3611, 903, 3613, 1807, 3615, 113, 3617, 1809, 3619, 905, 3621, 1811, 3623, 453, 3625, 1813, 3627, 907, 3629, 1815, 3631, 227, 3633, 1817, 3635, 909, 3637, 1819, 3639, 455, 3641, 1821, 3643, 911, 3645, 1823, 3647, 57, 3649, 1825, 3651, 913, 3653, 1827, 3655, 457, 3657, 1829, 3659, 915, 3661, 1831, 3663, 229, 3665, 1833, 3667, 917, 3669, 1835, 3671, 459, 3673, 1837, 3675, 919, 3677, 1839, 3679, 115, 3681, 1841, 3683, 921, 3685, 1843, 3687, 461, 3689, 1845, 3691, 923, 3693, 1847, 3695, 231, 3697, 1849, 3699, 925, 3701, 1851, 3703, 463, 3705, 1853, 3707, 927, 3709, 1855, 3711, 29, 3713, 1857, 3715, 929, 3717, 1859, 3719, 465, 3721, 1861, 3723, 931, 3725, 1863, 3727, 233, 3729, 1865, 3731, 933, 3733, 1867, 3735, 467, 3737, 1869, 3739, 935, 3741, 1871, 3743, 117, 3745, 1873, 3747, 937, 3749, 1875, 3751, 469, 3753, 1877, 3755, 939, 3757, 1879, 3759, 235, 3761, 1881, 3763, 941, 3765, 1883, 3767, 471, 3769, 1885, 3771, 943, 3773, 1887, 3775, 59, 3777, 1889, 3779, 945, 3781, 1891, 3783, 473, 3785, 1893, 3787, 947, 3789, 1895, 3791, 237, 3793, 1897, 3795, 949, 3797, 1899, 3799, 475, 3801, 1901, 3803, 951, 3805, 1903, 3807, 119, 3809, 1905, 3811, 953, 3813, 1907, 3815, 477, 3817, 1909, 3819, 955, 3821, 1911, 3823, 239, 3825, 1913, 3827, 957, 3829, 1915, 3831, 479, 3833, 1917, 3835, 959, 3837, 1919, 3839, 15, 3841, 1921, 3843, 961, 3845, 1923, 3847, 481, 3849, 1925, 3851, 963, 3853, 1927, 3855, 241, 3857, 1929, 3859, 965, 3861, 1931, 3863, 483, 3865, 1933, 3867, 967, 3869, 1935, 3871, 121, 3873, 1937, 3875, 969, 3877, 1939, 3879, 485, 3881, 1941, 3883, 971, 3885, 1943, 3887, 243, 3889, 1945, 3891, 973, 3893, 1947, 3895, 487, 3897, 1949, 3899, 975, 3901, 1951, 3903, 61, 3905, 1953, 3907, 977, 3909, 1955, 3911, 489, 3913, 1957, 3915, 979, 3917, 1959, 3919, 245, 3921, 1961, 3923, 981, 3925, 1963, 3927, 491, 3929, 1965, 3931, 983, 3933, 1967, 3935, 123, 3937, 1969, 3939, 985, 3941, 1971, 3943, 493, 3945, 1973, 3947, 987, 3949, 1975, 3951, 247, 3953, 1977, 3955, 989, 3957, 1979, 3959, 495, 3961, 1981, 3963, 991, 3965, 1983, 3967, 31, 3969, 1985, 3971, 993, 3973, 1987, 3975, 497, 3977, 1989, 3979, 995, 3981, 1991, 3983, 249, 3985, 1993, 3987, 997, 3989, 1995, 3991, 499, 3993, 1997, 3995, 999, 3997, 1999, 3999, 125]
%md ## Problem 7 Find the sum of greatest odd divisor of each of the number $2001, 2002, 2003, \dots, 4000$.

Problem 7

Find the sum of greatest odd divisor of each of the number 2001,2002,2003,,40002001, 2002, 2003, \dots, 4000.

%sage sum([max([k for k in divisors(N) if k%2==1]) for N in [2001..4000]])
4000000
%md # Testing

Testing