Skip to content

Instantly share code, notes, and snippets.

@graph226
Created February 24, 2017 08:02
Show Gist options
  • Save graph226/d6f8a481f1e7bd8511f11579f0a2c91e to your computer and use it in GitHub Desktop.
Save graph226/d6f8a481f1e7bd8511f11579f0a2c91e to your computer and use it in GitHub Desktop.
114514_prime
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import math\n",
"NUMBER = 100000000\n",
"\n",
"def get_prime_list(limit):\n",
" limit_sqrt = int(math.ceil(math.sqrt(limit)))\n",
" prime_bool_list = [False] * 2 + [True] * (limit - 2)\n",
" for prime_cand in range(2,limit_sqrt):\n",
" if prime_bool_list[prime_cand]:\n",
" for composite in range(prime_cand ** 2, limit, prime_cand):\n",
" prime_bool_list[composite] = False\n",
" return [i for i, b in enumerate(prime_bool_list) if b]\n",
"\n",
"prime_list = get_prime_list(NUMBER)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"1145141\n",
"1145143\n",
"11145143\n",
"11451403\n",
"11451449\n",
"11451467\n",
"11451497\n",
"11451499\n",
"21145141\n",
"31145143\n",
"81145147\n",
"91145149\n"
]
}
],
"source": [
"for prime in [str(prime) for prime in prime_list]:\n",
" if \"114514\" in prime:\n",
" print(prime)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "IPython (pyenv:3.5.1)",
"language": "python",
"name": "pyenv_3.5.1"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.1"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment