ADA Open Ended
ADA Open Ended
Your friend Antonio is not a cool guy. While talking to his girlfriend he started discussing coding problems.
Unfortunately, his girlfriend is also a pro-coder like you. Seeing Antonio trying to be over-smart she gives
him a positive integer K and asks to find a pair of positive integers a and b such that a*b=K and LCM (a, b)
is minimum.
In case there are multiple pairs, she wants one with the largest a.
Now, Antonio is unable to solve this problem and asks you to help. Help him to save his relationship.
LCM- lowest common multiple of two integers is the smallest positive integer that is multiple of both given
integers.
Input Format
• The first line contains a single integer denoting K.
Output Format
• In a single line print a and b (the answer to the query).
Constraints
• 1<=K<=10^3
TEST CASES
TEST CASE I
Sample Input I
36
Sample Output
66
TEST CSE II
Sample Input II
288
Sample Output
24 12
GROUP (*arr,k,*arr21,*arr22,no_group,*arr3)
For i=1 to no_group
For j=1 to no_group
if(arr[i]*arr[j] == k)
arr21[j] <- arr[i]
arr22[j] <- arr[j]
arr3[j] <- lcm(arr21[j],arr22[j])
end of loop 1
end of loop0 2
declare int res <- arr3[1],loc <- 0;
for i = 1 to no_group
res <- min(res, arr3[i])
for no_group to 1
if(arr3[i]==res)
loc <- i
CODE:
#include<iostream>
int factors_count(int K)
{
int count = 0;
for(int i=1;i<=K;i++)
{
if(K%i == 0)
{
count++;
}
}
return count;
}
}
int main()
{
int K;
cout<<"Enter the positive number:";
cin>>K;
int n=factors_count(K);
int *arr = new int(n);
int *arr3 = new int(n);
int *arr21 = new int(n);
int *arr22 = new int(n);
factors(K,arr,0);
group(arr,K,arr21,arr22,n,arr3);
return 0;
}
OUTPUT:
CODE:
#include<iostream>
#include <unordered_set>
using namespace std;
int factors_count(int K)
{
int count = 0;
for(int i=1;i<=K;i++)
{
if(K%i == 0)
{
count++;
}
}
return count;
}
}
int res = arr3[0],loc = 0,count =0;
for (int i = 1; i < no_group; i++)
{
res = min(res, arr3[i]);
}
for(int i=no_group-1;i>=0;i--)
{
if(arr3[i]==res)
loc =i;
}
unordered_set<int> :: iterator itr;
int main()
{
int K;
cout<<"Enter the positive number:";
cin>>K;
int n=factors_count(K);
int *arr = new int(n);
int *arr3 = new int(n);
factors(K,arr,0);
group(arr,K,n,arr3);
return 0;
}
OUTPUT: