// Arup Guha
// 8/31/2023
// Code for COP 3502 Quiz 1 Version C Question 2

#include <stdio.h>
#include <stdlib.h>

int mult_to_target(int list[], int n, int target);

int main() {

    int vals[10] = {1,4,5,19,22,25,30,37,45,60};

    for (int i=1; i<=2700; i++)
        if (mult_to_target(vals, 10, i))
            printf("%d ", i);
    printf("\n");
    return 0;
}

// Pre-condition: list is length n, sorted, with unique values.
// Post-condition: Returns 1 if two different values in list multiply
//                 to exactly target, and 0 if no such pair exists.
int mult_to_target(int list[], int n, int target) {

    int i = 0, j = n-1;

    // Stop before they meet.
    while ( i<j ) {

        // Too small, increase smaller number.
        if (list[i]*list[j] < target)
            i++;

        // Too big decrease larger number.
        else if (list[i]*list[j] > target)
            j--;

        // We got it!
        else
            return 1;
     }

     // No answer...
     return 0 ;
}
