Last active
April 19, 2019 14:08
-
-
Save h8nor/f7ee3148292f7d8e45df to your computer and use it in GitHub Desktop.
Calculating the square root of a natural number
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
Option Explicit | |
'12345678901234567890123456789012345bopoh13@ya67890123456789012345678901234567890 | |
Function Square_root_Diophantine(ByVal Square_number As Long) As Currency | |
Dim Number As Integer: Const Rank_places As Long = 10 ^ 2 | |
Do While Square_number > Number | |
Number = Number + 1 | |
Square_number = Square_number - 2 * Number | |
Loop: Square_root_Diophantine = Number ' Square_root for N | |
' https://habr.com/post/448558/#comment_20047920 | |
If Not Abs(Square_number) = Number Then Square_root_Diophantine = Number + _ | |
((Number + Square_number) * Rank_places \ (Number * 2 + 1)) * 1 / Rank_places ' ~= | |
End Function | |
Sub Time_spent_Testing() ' i = 16383 | |
Dim i As Long, Begin As Double: Begin = Timer | |
For i = 4000 To 6000: Debug.Print Square_root_Diophantine(i ^ 2): Next i | |
'For i = 4000 To 6000: Debug.Print Sqr(i ^ 2): Next i | |
Debug.Print Format(Timer - Begin, "0.000 сек") | |
End Sub |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment