def list_reduced_fractions(d): count = 1 fractions_list = [(1, d)] for n in range(2, d): if common.get_gcd(n, d) == 1: count += 1 fractions_list.append((n, d)) return (count, fractions_list)
def count_reduced_fractions(max_d): count = 0 # Even denominators for d in range(2, max_d+1, 2): count += 1 # always count 1/d. for n in range(3, d, 2): # Check only odd numerators if common.get_gcd(n, d) == 1: count += 1 # Odd denominators for d in range(3, max_d+1, 2): if common.is_prime_mr(d): count += d - 1 else: count += 2 # always count 1/d and 2/d for odd d. for n in range(3, d): if common.get_gcd(n, d) == 1: count += 1 return count