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
limit = 10**6 | |
prime = [True]*limit | |
for i in range(3, int(limit**.5) + 1, 2): | |
if prime[i]: | |
prime[i*i: : 2*i] = [False]*len(range(i*i, limit, 2*i)) | |
primes = [2] + [i for i in range(3, limit, 2) if prime[i]] | |
print(len(primes)) |
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
limit = 10**6 | |
prime = [True]*limit | |
for i in xrange(3, int(limit**.5) + 1, 2): | |
if prime[i]: | |
prime[i*i: : 2*i] = [False]*len(xrange(i*i, limit, 2*i)) | |
primes = [2] + [i for i in xrange(3, limit, 2) if prime[i]] | |
print len(primes) |
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
import numpy | |
prime = numpy.ones(limit/2, dtype=numpy.bool) | |
for i in xrange(3, int(limit**.5) + 1, 2): | |
if prime[i/2]: | |
prime[i*i/2: : i] = False | |
primes = 2*prime.nonzero()[0] + 1 | |
primes[0] = 2 |
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
limit = 12345678 | |
prime = [True]*limit | |
for i in xrange(3, int(limit**.5) + 1, 2): | |
if prime[i]: | |
prime[i*i : : 2*i] = [False]*len(xrange(i*i, limit, 2*i)) | |
prime[4 : : 2] = [False]*len(xrange(4, limit, 2)) # all even | |
prime[0] = prime[1] = False | |
pre = [] |
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
import os | |
import random | |
import sys | |
import zipfile | |
try: | |
os.mkdir('input') | |
os.mkdir('output') | |
except OSError: | |
pass |
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
for _ in xrange(int(raw_input())): | |
s = raw_input() | |
if s[0] == 'R': | |
a, b = s[1:].split('C') | |
b = int(b) | |
ret = [] | |
while b: | |
b, r = divmod(b, 26) | |
if r == 0: | |
r = 26 |
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
n = int(raw_input()) | |
for i in xrange(n): | |
print '%*s' % (n, '#'*(i + 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
import urllib | |
url = 'http://example.com/' | |
igd = 'https://is.gd/create.php' | |
data = urllib.urlencode({ | |
'url': url, | |
'opt': 1, | |
'format': 'simple' | |
}) |
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
for _ in xrange(int(raw_input())): | |
n = int(raw_input()) | |
b = bin(n)[2: ] | |
i = len(b) - len(b.rstrip('0')) + b.count('1') | |
print ['Louise', 'Richard'][i%2] |
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
import requests | |
import json | |
r = requests.get('https://graph.facebook.com/838978412886942/invitable_friends?fields=picture{url}&limit=1000&access_token=_your_token_') | |
data = json.loads(r.text) | |
dpids = [i['picture']['data']['url'].split('_', 2)[1] for i in data['data']] | |
ind = 0 | |
for i, dpid in enumerate(dpids, 1): | |
while True: |