def cache(f): """ simple hash cache. Makes key by: ''.join(str(a) for a in args) Will choke on kwargs for the moment. """ cache_data = {} def _(*args): key = ''.join(str(a) for a in args) try: print len(cache_data) return cache_data[key] except KeyError: res = f(*args) cache_data[key] = res return res return _ # @cache primes = {} def isPrime(num): n = 2 while n < num: if num % n == 0: primes[n] = False return False n += 1 primes[num] = True return True # greatest prime factor def gpf(n): i = 2 while 1: # print i/float(n) if (n % i == 0): print i, n/i, isPrime(i), isPrime(n/i) if (isPrime(n/i)): return i i += 1 if __name__ == '__main__': print gpf(317584931803);