Skip to content

Instantly share code, notes, and snippets.

@20chan
Created May 2, 2018 02:24
Show Gist options
  • Select an option

  • Save 20chan/1b167ca6df5c250f45e8834dc228b0d5 to your computer and use it in GitHub Desktop.

Select an option

Save 20chan/1b167ca6df5c250f45e8834dc228b0d5 to your computer and use it in GitHub Desktop.
MAGIC NUMBER 10103
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": [
"def primes(n):\n",
" sieve = [True] * n\n",
" for i in range(3,int(n**0.5)+1,2):\n",
" if sieve[i]:\n",
" sieve[i*i::2*i]=[False]*((n-i*i-1)//(2*i)+1)\n",
" return [2] + [i for i in range(3,n,2) if sieve[i]]"
]
},
{
"cell_type": "code",
"execution_count": 34,
"metadata": {},
"outputs": [],
"source": [
"p = primes(10000000)\n",
"ps = [n for n in p if n > 1000]\n",
"notps = [n for n in range(2, 1000) if not n in p]"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"no..\n"
]
}
],
"source": [
"# 모든 합성수들에 대해서 결과값이 1이 아닌 소수를 찾는 코드.\n",
"for prime in ps:\n",
" for notp in notps:\n",
" if prime ** ~-notp % notp == 1:\n",
" break\n",
" else:\n",
" print(prime)\n",
" break\n",
"else:\n",
" print('no..')"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"561\n",
"645\n",
"946\n"
]
}
],
"source": [
"# 10103 이 안되는 케이스들을 골라보자\n",
"for notp in notps:\n",
" if 10103 ** ~-notp % notp == 1:\n",
" print(notp)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"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.6.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment