From a77de5ec62d94f690dc691138433a2f244f186cb Mon Sep 17 00:00:00 2001 From: rjrahul10 <43719845+rjrahul10@users.noreply.github.com> Date: Wed, 16 Oct 2019 14:56:21 +0530 Subject: [PATCH] Create msv.cpp --- codechef/msv.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 codechef/msv.cpp diff --git a/codechef/msv.cpp b/codechef/msv.cpp new file mode 100644 index 0000000..b4cf9cd --- /dev/null +++ b/codechef/msv.cpp @@ -0,0 +1,48 @@ +#include +#include +#include +using namespace std; +int main() +{ + #ifndef ONLINE_JUDGE + freopen("input.txt","r", stdin); + freopen("output.txt","w", stdout); + #endif + ios_base::sync_with_stdio(0); + cin.tie(0); + cout.tie(0); + int t,i,j,n,msv,icount; + cin>>t; + while(t--) + { + msv =0; // if all integers are co prime to every other element + cin>>n; + vector vis(n,false); // if a no. is visited + vector a(n); + for(i=0;i>a[i]; + if(a[i]==1) //coz 1 can divide anyone + msv=i; + } + + for(i=n-1;i>msv;i--) + { icount =0; + if(a[i]==1) + break; + j =i; + if(vis[i]==true) // no. visited + continue; + while(j--) + { + if(a[j]%a[i]==0) + {icount++; + vis[j] = true; + } + } + vis[i] = true; + msv = max(icount,msv); // check for maximum + } + cout<