Skip to content

Instantly share code, notes, and snippets.

@yosuketanaka
Created October 19, 2011 13:47
Show Gist options
  • Save yosuketanaka/1298322 to your computer and use it in GitHub Desktop.
Save yosuketanaka/1298322 to your computer and use it in GitHub Desktop.
project euler 1-10
qlist = [i for i in range (1000) if i % 3 == 0 or i % 5 == 0]
sum = 0
for i in qlist:
sum += i
print sum
result = []
a, b = 1, 2
while a < 4000000:
result.append(a)
a, b = b, a+b
sum = 0
for i in result:
if i % 2 == 0:
sum += i
print sum
x = 600851475143
while x >= 4 and x % 2 == 0:x /= 2
d = 3; q = x / d
while q >= d:
if x % d == 0:x = q
else:d += 2
q = x / d
print "%d" % x
c = 0
plist = [i for i in range(100000,1000000) if i/100000==i%10 and i/10000-(i/100000)*10==((i%100)-(i%10))/10 and i/1000-(i/10000)*10==((i%1000)-(i%100))/100]
jlist = [j for j in range(110, 1001, 11)]
for j in jlist:
for i in plist:
if i%j==0 and i/j<1000:
if i>c:c=i
print c
c=2*3*5*7*11*13*17*19
for i in range(1,21):
if c % i != 0:c*=i/(c%i)
print c
plist = [i for i in range(1,101)]
sum1, sum2=0, 0
for i in plist:
sum1 += i
sum2 += i**2
print sum1**2-sum2
a = range(150000)
a[1] = 0
for p in a:
if not p:continue
elif p > 387:break
else:
for multi in xrange(p+p, 150000, p):
a[multi] = 0
a = [x for x in a if x]
print a[10000]
plist="7316717653133062491922511967442657474235534919493496983520312774506326239578318016984801869478851843858615607891129494954595017379583319528532088055111254069874715852386305071569329096329522744304355766896648950445244523161731856403098711121722383113622298934233803081353362766142828064444866452387493035890729629049156044077239071381051585930796086670172427121883998797908792274921901699720888093776657273330010533678812202354218097512545405947522435258490771167055601360483958644670632441572215539753697817977846174064955149290862569321978468622482839722413756570560574902614079729686524145351004748216637048440319989000889524345065854122758866688116427171479924442928230863465674813919123162824586178664583591245665294765456828489128831426076900422421902267105562632111110937054421750694165896040807198403850962455444362981230987879927244284909188845801561660979191338754992005240636899125607176060588611646710940507754100225698315520005593572972571636269561882670428252483600823257530420752963450"
c = 1
for x in range(996):
d = 1
for i in range(x,x+5):d*=int(plist[i])
if d > c:c = d
print c
for i in range(1,333):
for j in range(1,1000):
if (1000-i)*(1000-j) == 500000:
c, x = 1, 1
c = 1000-i-j
x = c*i*j
print x
a = range(2000000)
a[1] = 0
for p in a:
if not p:continue
elif p > 1414:break
else:
for multi in xrange(p+p, 2000000, p):
a[multi] = 0
a = [x for x in a if x]
sum = 0
for i in a:sum += i
print sum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment