Last active
September 4, 2020 05:14
-
-
Save foxqstm/c0f89162a5997b6c5c4337593081bc8e to your computer and use it in GitHub Desktop.
Intsqrt
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": 5, | |
"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", | |
" sqnf=math.sqrt(n)\n", | |
" dig=math.ceil(math.log10(sqnf))\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
Exact function which gives maximum integer m < sqrt(n) for given n.