def check(n): '''checks if n, kn have the same digits''' L=aritmetica.digitos(n) for k in range(2,7): Lk=aritmetica.digitos(n*k) if sorted(L)!= sorted(Lk): return False return True
def permuta3(m): C=[] for p in next_permutation(sorted(digitos(m))): k=l2i(p) if k in CUBOS: C.append(k) return set(C)
def Bouncy(n): l = digitos(n) if len(l)<3: return False SG=map(signo,[par[1]-par[0] for par in pairwise(l)]) #print SG if 1 in SG and -1 in SG: return True else: return False
from operator import mul from aritmetica import factorial print "precalculando..." CUBOS = {n**3 for n in range(10**6)} DIGITOS=[1,2,3,4,5,6,7,8,9,0] D={} def lista2num(L): l=L[::-1] return sum( [a*10**(k) for (k,a) in enumerate(l)]) def overcount(p): repeticiones= map(factorial, filter(lambda x: x>1, [p.count(d) for d in range(10)])) sobreconteo = reduce(mul, repeticiones, 1) return sobreconteo for n in xrange(1,1000): dig = digitos(n**3) #print dig v={lista2num(p) for p in permutations(dig) if lista2num(p) in CUBOS and p[0]!=0} ncubos = len(v) #print n, n**3, "\t",len(v), ncubos, v if ncubos == 5: print n break print overcount(digitos(345**3)) print 345**3
def f(n): return sum(map(factorial, digitos(n)))
# -*- coding: utf-8 -*- '''Problem 70 Euler's Totient function, φ(n) [sometimes called the phi function], is used to determine the number of positive numbers less than or equal to n which are relatively prime to n. For example, as 1, 2, 4, 5, 7, and 8, are all less than nine and relatively prime to nine, φ(9)=6. The number 1 is considered to be relatively prime to every positive number, so φ(1)=1. Interestingly, φ(87109)=79180, and it can be seen that 87109 is a permutation of 79180. Find the value of n, 1 < n < 107, for which φ(n) is a permutation of n and the ratio n/φ(n) produces a minimum.''' from __future__ import division from aritmetica import factoriza from aritmetica import totient from aritmetica import ndigitos from aritmetica import digitos import aritmetica import time Tt=time.time() MIN=1.1 for n in xrange(2,10**7): t = totient(n) #print n, t if (ndigitos(t) == ndigitos(n)) and (n/t<MIN) and (sorted(digitos(t))==sorted(digitos(n))): print n, t, n/t MIN=n/t print "\n====\n", time.time()-Tt
def f(n): return sum([Factoriales[d] for d in digitos(n)])
from aritmetica import digitos from collections import Counter C = {} #Fill the dictionary SOLUTIONS = set() for n in xrange(2,10000): z=tuple(sorted(digitos(n**3))) D= C.get(z,[]) D.append(n) C[z] = D MINI = 100000000 for k in C: if len(C[k])==5: newmin = min(C[k]) if newmin < MINI: MINI = newmin print MINI**3