How to resolve the algorithm First power of 2 that has leading decimal digits of 12 step by step in the Visual Basic .NET programming language
Published on 12 May 2024 09:40 PM
How to resolve the algorithm First power of 2 that has leading decimal digits of 12 step by step in the Visual Basic .NET programming language
Table of Contents
Problem Statement
(This task is taken from a Project Euler problem.) (All numbers herein are expressed in base ten.)
27 = 128 and 7 is the first power of 2 whose leading decimal digits are 12. The next power of 2 whose leading decimal digits are 12 is 80, 280 = 1208925819614629174706176.
Define p(L,n) to be the nth-smallest value of j such that the base ten representation of 2j begins with the digits of L .
You are also given that:
Let's start with the solution:
Step by Step solution about How to resolve the algorithm First power of 2 that has leading decimal digits of 12 step by step in the Visual Basic .NET programming language
Source code in the visual programming language
Module Module1
Function Func(ByVal l As Integer, ByVal n As Integer) As Long
Dim res As Long = 0, f As Long = 1
Dim lf As Double = Math.Log10(2)
Dim i As Integer = l
While i > 10
f *= 10
i /= 10
End While
While n > 0
res += 1
If CInt((f * Math.Pow(10, res * lf Mod 1))) = l Then
n -= 1
End If
End While
Return res
End Function
Sub Main()
Dim values = {Tuple.Create(12, 1), Tuple.Create(12, 2), Tuple.Create(123, 45), Tuple.Create(123, 12345), Tuple.Create(123, 678910), Tuple.Create(99, 1)}
For Each pair In values
Console.WriteLine("p({0,3}, {1,6}) = {2,11:n0}", pair.Item1, pair.Item2, Func(pair.Item1, pair.Item2))
Next
End Sub
End Module
You may also check:How to resolve the algorithm Dot product step by step in the ACL2 programming language
You may also check:How to resolve the algorithm Bitwise operations step by step in the Standard ML programming language
You may also check:How to resolve the algorithm Shell one-liner step by step in the Lasso programming language
You may also check:How to resolve the algorithm Permutations step by step in the OCaml programming language
You may also check:How to resolve the algorithm Kronecker product step by step in the Lua programming language