Beispiel #1
0
def main():
    """Main program."""
    answer = 0
    start_time = time.time()
    d = 2
    lim = 1000000
    while d <= lim:
        answer += nt.phi(d)
        d += 1
    end_time = time.time()
    print("The answer is %d" % answer)
    print("%f seconds elapsed." % (end_time - start_time))

    import pyperclip
    pyperclip.copy(str(answer))
    print("The answer has been placed in the clipboard.")
    def test_phi(self):
        """Tests for phi()."""
        expected = [
            1,
            1,
            2,
            2,
            4,
            2,
            6,
            4,
            6,
            4,
            10,
            4,
            12,
            6,
            8,
            8,
            16,
            6,
            18,
            8,
            12,
            10,
            22,
            8,
            20,
            12,
            18,
            12,
            28,
            8,
            30,
            16,
            20,
            16,
            24,
            12,
            36,
            18,
            24,
            16,
            40,
            12,
            42,
            20,
            24,
            22,
            46,
            16,
            42,
            20,
            32,
            24,
            52,
            18,
            40,
            24,
            36,
            28,
            58,
            16,
            60,
            30,
            36,
            32,
            48,
            20,
            66,
            32,
            44,
        ]

        for x, p in enumerate(expected):
            n = x + 1  # array is zero based but answers are one based
            result = nt.phi(n)
            m = "Expected " + str(p) + " but got " + str(result) + " for n = " + str(n)
            self.assertEquals(p, result, m)