• API
• FAQ
• Tools
• Archive
daily pastebin goal
5%
SHARE
TWEET

# Untitled

a guest Jan 17th, 2019 49 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. # I have decided to tackle this one in Python rather than PHP as I could quite happily do this in PHP but the point of doing these exercises is to expand my knowledge of multiple languages rather than just "solve them".
2. #
3. # Going forward it will likely be a mix of languages, I imagine it will rpimarily be PHP and Python.
4. #
5. # The prime factors of 13195 are 5, 7, 13 and 29.
6. #
7. # What is the largest prime factor of the number 600851475143?
8.
9. import math
10.
11. def gen_max_prime(n):
12.     while(not(n & 1)):
13.         result = 2
14.         n >>= 1
15.
16.     for i in range(3,int(math.sqrt(n)) + 1,2):
17.         while n % i == 0:
18.             result = i
19.             n = n / i
20.
21.     if n > 2:
22.         result = n
23.
24.     return int(result)
25.
26. print gen_max_prime(600851475143) # Returns 6857
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.

Top