Chef and Linear Chess Problem Code: LINCHESS Solution Codechef

 #include <bits/stdc++.h>
using namespace std;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  int t;
  cin>>t;
  while(t--){
    int n,k;
    cin>>n>>k;
    int ans=-1;
    for(int i=0;i<n;i++){
      int x;
      cin>>x;
      if(k%x==0&&x>ans)ans=x;
    }
    cout<<ans<<'\n';
  }
  return 0;
}

Comments