Created
October 26, 2011 04:57
-
-
Save yosuketanaka/1315480 to your computer and use it in GitHub Desktop.
project euler 21-28
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sum=[1 for i in range(10001)] | |
xsum=0 | |
for j in range(3,10001): | |
i = 2 | |
while True: | |
if j%i==0:sum[j] += (i+j/i) | |
if i**2==j:sum[j] -= i | |
if i**2>j:break | |
i += 1 | |
for j in range(1,10001): | |
if sum[j]<10000: | |
if sum[sum[j]]==j and sum[j]!=j:xsum+=j | |
print xsum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
f1=None | |
try: | |
f1 = open("names.txt","r") | |
data = f1.read() | |
except IOError, inst: | |
print inst | |
finally: | |
if f1:f1.close() | |
data=data.split(',') | |
data.sort() | |
ssum=0 | |
for j in range(len(data)): | |
psum=j+1 | |
sum=0 | |
for i in range(1,len(data[j])-1): | |
sum+=ord(data[j][i])-64 | |
psum*=sum | |
ssum+=psum | |
print ssum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sum=[1 for i in range(28124)] | |
for j in range(12,28124): | |
i = 2 | |
while True: | |
if i**2>j:break | |
if j%i==0:sum[j] += (i+j/i) | |
if i**2==j:sum[j] -= i | |
i += 1 | |
for j in range(28124): | |
if sum[j]>j:sum[j]=j | |
else:sum[j]=0 | |
sum[1]=0 | |
sum=[x for x in sum if x] | |
b=[i for i in range(28124)] | |
for i in sum: | |
for j in sum: | |
if i+j<28124: | |
b[i+j]=0 | |
b=[x for x in b if x] | |
ysum=0 | |
for x in b:ysum+=x | |
print ysum |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pro(i): | |
p=1 | |
for x in range(1,i+1):p*=x | |
return p | |
a=[i for i in range(10)] | |
b=999999 | |
c=range(10) | |
for j in range(10): | |
i=0 | |
while True: | |
if b < (i+1)*pro(9-j): | |
c[j]=a[i] | |
b-=(i)*pro(9-j) | |
a.pop(i) | |
break | |
i += 1 | |
print c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
result = [] | |
a, b = 1, 1 | |
while True: | |
result.append(a) | |
a, b = b, a+b | |
if a > 10**999:break | |
print len(result)+1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
imax=0 | |
jmax=0 | |
x=(2**9)*(5**4) | |
for i in range(1,1000): | |
j=1 | |
if x%i!=0: | |
while True: | |
if x*(10**j-1)%i!=0:j+=1 | |
else:break | |
if jmax<j: | |
jmax=j | |
imax=i | |
print imax |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = range(1000) | |
a[1] = 0 | |
for p in a: | |
if not p:continue | |
elif p > 31:break | |
else: | |
for multi in xrange(p+p, 1000, p): | |
a[multi] = 0 | |
a = [x for x in a if x] | |
n=0 | |
while True: | |
if n**2-79*n+1601 in a:break | |
else: n+=1 | |
y=n**2-79*n+1601 | |
x=-79+2*n | |
print x*y |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a=[2*n for n in range(1,501)] | |
y=1 | |
sum=1 | |
for x in a: | |
sum+=y+x+y+2*x+y+3*x+y+4*x | |
y+=4*x | |
print sum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment