Created
September 8, 2020 06:28
-
-
Save foxqstm/5d7300ffc54cb50268fc017e9f2396e5 to your computer and use it in GitHub Desktop.
Intsqrt ver2
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
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 6, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"name": "stdout", | |
"output_type": "stream", | |
"text": [ | |
"n= 2354238731807548037258146419529716451839613714656910835753827857171\n", | |
"n-sq**2 1439379138857298146653197327252975\n", | |
"log10(diff),log10(sq) 33.15817520410052 33.18592525020733\n" | |
] | |
} | |
], | |
"source": [ | |
"import math\n", | |
"\n", | |
"def intsqrt(n):\n", | |
" dig=0\n", | |
" while pow(10,2*dig) < n:\n", | |
" dig+=1\n", | |
" \n", | |
" sq=0\n", | |
" for k in reversed(range(0,dig+1)):\n", | |
" for l in range(0,10):\n", | |
" sq+=10**k\n", | |
" if sq*sq==n:\n", | |
" break\n", | |
" if sq*sq>n:\n", | |
" sq-=10**k\n", | |
" break\n", | |
" return sq\n", | |
"\n", | |
"n=2354238731807548037258146419529716451839613714656910835753827857171\n", | |
"sq=intsqrt(n)\n", | |
"diff=n-sq*sq\n", | |
"print('n=',n)\n", | |
"print('n-sq**2',diff)\n", | |
"print('log10(diff),log10(sq)',math.log10(diff),math.log10(sq))" | |
] | |
} | |
], | |
"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.5" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment