My issue
it show wrong answer on this approach.
k>=n
x<K and n-x<k so their product after module =x*(n-x)
k<n
running a loop for finding max value at each value of x in else case.
My code
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
int main() {
int t;cin>>t;
while(t--){
int n,k;
cin>>n>>k;
if(k==1||k==2)
cout<<0<<endl;
else if(n<=k)
n&1?cout<<((n+1)/2)<<endl:cout<<(n/2)<<endl;
else{
int x=0,maxi=0,ans=0;
while(x<=n){
if(maxi<((x%k)*((n-x)%k))){
ans=x;
maxi=(x%k)*((n-x)%k);
}
x++;
}
cout<<ans<<endl;
}
}
return 0;
}
Problem Link: MAXIMALEXP Problem - CodeChef