Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def prime(num):
- # create dictionary of prime factors with counts
- factor = 2
- factors = {}
- while num > 1:
- if num % factor == 0:
- if factor not in factors:
- factors[factor] = 1
- else:
- factors[factor] += 1
- num /= factor
- else:
- factor += 1
- return factors
- def main():
- # Find target number by multiplying prime factors together to find number divisible by all positive numbers <= divisor
- divisor = 10000
- i = 2
- prime_factor_count = {}
- while divisor > 1:
- add_factor_count = prime(divisor)
- for factor in add_factor_count:
- if factor not in prime_factor_count or add_factor_count[factor] > prime_factor_count[factor]:
- prime_factor_count[factor] = add_factor_count[factor]
- divisor -= 1
- target = 1
- for factor in prime_factor_count:
- target *= factor ** prime_factor_count[factor]
- print target
- main()
Add Comment
Please, Sign In to add comment