Created
May 2, 2018 02:24
-
-
Save 20chan/1b167ca6df5c250f45e8834dc228b0d5 to your computer and use it in GitHub Desktop.
MAGIC NUMBER 10103
This file contains hidden or 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
| { | |
| "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