My issue
It is Showing time limit exceeded.
pls tell me a simple solution i can use to solve this!
My code
#include <iostream>
#include <vector>
#include <string>
using namespace std;
void solve(){
int n;
cin>>n;
int ans{0};
int max{0};
if(n%2==0){
ans=n;
}
else if(n%2!=0){
for(int i=1;i<=n;i++){
if(n%i>max){
max=n%i;
ans=i;
}
}
}
cout<<ans<<endl;
}
int main(){
int n;
cin>>n;
while(n--){
solve();
}
}
Problem Link: MUFFINS3 Problem - CodeChef