Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,894 questions

51,825 answers

573 users

How to find whether an array include a pair of which product equals to N in VB.NET

1 Answer

0 votes
Imports System
Imports System.Collections.Generic

Public Class Program
    Private Shared Function ProductExists(ByVal arr As Integer(), ByVal N As Integer) As Boolean
        Dim size As Integer = arr.Length

        If size < 2 Then
            Return False
        End If

        Dim st As HashSet(Of Integer) = New HashSet(Of Integer)()

        For i As Integer = 0 To size - 1
            If arr(i) = 0 AndAlso N = 0 Then
                Return True
            End If

            If N Mod arr(i) = 0 Then
                If st.Contains(N / arr(i)) Then
                    Return True
                End If
                st.Add(arr(i))
            End If
        Next

        Return False
    End Function

    Public Shared Sub Main(ByVal args As String())
        Dim arr As Integer() = New Integer() {5, 7, 13, 25, 9, 3, 4}
        Dim N As Integer = 21

        If ProductExists(arr, N) Then
            Console.WriteLine("Yes")
        Else
            Console.WriteLine("No")
        End If
    End Sub
End Class



' run:
'
' Yes
'

 



answered Jul 21, 2023 by avibootz
...