Ad
Code
Diff
  • bool Nand(bool a, bool b) {
        return 1 - (a * b);
    }
    
    bool Not(bool a) {
        return Nand(a, a);
    }
    
    bool And(bool a, bool b) {
        return Not(Nand(a, b));
    }
    
    bool Nor(bool a, bool b) {
        return And(Not(a), Not(b));
    }
    
    bool Or(bool a, bool b) {
        return Not(Nor(a, b));
    }
    
    bool Xor(bool a, bool b) {
        return And(Or(a, b), Not(And(a, b)));
    }
    
    bool Buffer(bool a) {
        return Not(Not(a));
    }
    
    bool Xnor(bool a, bool b) {
        return Not(Xor(a, b));
    }
    
    bool False(bool a) {
        return And(a, Not(a));
    }
    
    bool True(bool a) {
        return Or(a, Not(a));
    }
    • bool Nand(bool a, bool b){
    • return 1-(a*b);
    • bool Nand(bool a, bool b) {
    • return 1 - (a * b);
    • }
    • bool Not(bool a){
    • return Nand(a, a);
    • bool Not(bool a) {
    • return Nand(a, a);
    • }
    • bool And(bool a, bool b){
    • return Not(Nand(a, b));
    • bool And(bool a, bool b) {
    • return Not(Nand(a, b));
    • }
    • bool Nor(bool a, bool b){
    • return And(Not(a), Not(b));
    • bool Nor(bool a, bool b) {
    • return And(Not(a), Not(b));
    • }
    • bool Or(bool a, bool b){
    • return Not(Nor(a, b));
    • bool Or(bool a, bool b) {
    • return Not(Nor(a, b));
    • }
    • bool Xor(bool a, bool b){
    • return And(Or(a, b), Not(And(a, b)));
    • bool Xor(bool a, bool b) {
    • return And(Or(a, b), Not(And(a, b)));
    • }
    • bool Buffer(bool a){
    • return Not(Not(a));
    • bool Buffer(bool a) {
    • return Not(Not(a));
    • }
    • bool Xnor(bool a, bool b){
    • return Not(Xor(a, b));
    • bool Xnor(bool a, bool b) {
    • return Not(Xor(a, b));
    • }
    • bool False(bool a){
    • return And(a, Not(a));
    • bool False(bool a) {
    • return And(a, Not(a));
    • }
    • bool True(bool a){
    • return Or(a, Not(a));
    • bool True(bool a) {
    • return Or(a, Not(a));
    • }
Code
Diff
  • def count_prime(n, prime, factors):
        count = 0
        while n % prime == 0: 
            count += 1
            n //= prime
        if count: 
            factors.append((prime, count))
        return n, factors
    
    def prime_factorization(n):
        factors = []
        n, factors = count_prime(n, 2, factors)
        prime = 3
        while prime * prime <= n:
            n, factors = count_prime(n, prime, factors)
            prime += 2
        if n > 1: 
            factors.append((n, 1))
        return factors
    • def count_prime(n, prime, factors):
    • count = 0
    • while n % prime == 0:
    • count += 1
    • n //= prime
    • if count:
    • factors.append((prime, count))
    • return n, factors
    • def prime_factorization(n):
    • factors = []
    • n, factors = count_prime(n, 2, factors)
    • prime = 3
    • while prime * prime <= n:
    • n, factors = count_prime(n, prime, factors)
    • prime += 2
    • if n > 1:
    • factors.append((n, 1))
    • return factors
Code
Diff
  • def prime_factorization(n):
        factors = []
        cnt = 0
        while n % 2 == 0: cnt += 1; n //= 2
        if cnt: factors.append((2, cnt))
        i = 3
        while i * i <= n:
            cnt = 0
            while n % i == 0: cnt += 1; n //= i
            if cnt: factors.append((i, cnt))
            i += 2
        if n > 1: factors.append((n, 1))
        return factors
    • def prime_factorization(n):
    • factors = []
    • cnt = 0
    • while n % 2 == 0: cnt += 1; n //= 2
    • if cnt: factors.append((2, cnt))
    • cnt = 0
    • while n % 3 == 0: cnt += 1; n //= 3
    • if cnt: factors.append((3, cnt))
    • i = 5
    • i = 3
    • while i * i <= n:
    • cnt = 0
    • while n % i == 0: cnt += 1; n //= i
    • if cnt: factors.append((i, cnt))
    • cnt = 0
    • i += 2
    • while n % i == 0: cnt += 1; n //= i
    • if cnt: factors.append((i, cnt))
    • i += 4
    • if n > 1: factors.append((n, 1))
    • return factors
Code
Diff
  • def prime_factorization(input_number):
        factors = []
        for i in range(2, int(input_number**0.5) + 1):
            while input_number % i == 0:
                factors.append(i)
                input_number //= i
        if input_number > 1:
            factors.append(input_number)
        from collections import Counter
        return sorted(Counter(factors).items())
    • def prime_factorization(input_number):
    • factors = []
    • while input_number % 2 == 0:
    • factors.append(2)
    • input_number //= 2
    • for i in range(3, int(input_number**0.5) + 1, 2):
    • for i in range(2, int(input_number**0.5) + 1):
    • while input_number % i == 0:
    • factors.append(i)
    • input_number //= i
    • if input_number > 2:
    • if input_number > 1:
    • factors.append(input_number)
    • from collections import Counter
    • factor_count = Counter(factors)
    • return sorted(factor_count.items())
    • return sorted(Counter(factors).items())

You are tasked with writing a Python function that performs prime factorization on a given integer. The function should return a list of tuples, where each tuple contains a prime factor and its exponent in the factorization.

Requirements:
The function should handle positive integers greater than 1.

The function should return a list of tuples, where each tuple contains a prime factor and its exponent.

The list should be sorted in ascending order based on the prime factors.

Example:

input_number = 84 output_list = prime_factorization(input_number) print(output_list) Expected Output: [(2, 2), (3, 1), (7, 1)]

def prime_factorization(input_number):
    factors = []
    while input_number % 2 == 0:
        factors.append(2)
        input_number //= 2
    for i in range(3, int(input_number**0.5) + 1, 2):
        while input_number % i == 0:
            factors.append(i)
            input_number //= i
    if input_number > 2:
        factors.append(input_number)
    from collections import Counter
    factor_count = Counter(factors)
    return sorted(factor_count.items())