0
How to make this more time efficient??
#include <iostream> #include<math.h> using namespace std; int lcm(int a,int b) { for(int i=max(a,b) ; ;i++) { if(i%a==0 && i%b==0) return i; } } int main() { // your code goes here int n; cin>>n; int a[n]; for(int i=0 ;i<n ;i++) cin>>a[i]; int maxa=0; for(int i= 0 ; i<n ;i++) { for(int j=i+1 ;j<n ;j++) { maxa=max(maxa,lcm(a[i],a[j])); } } cout<<maxa; return 0; }
3 Réponses
0
I hv used the nested loop to make all posssible pairs from the array
0
Nooo , the task is to make pairs from the array and find the maximum lcm from it
0
Sorry i could not upload the question .
But thanks for the response☺