My issue
please give test cases for which my code is failing or logic to fix that corner test case which my code is unable to click
My code
#include <stdio.h>
long long sumOfPositiveIntegers(int x, int y) {
return (y - x + 1) * (x + y) / 2;
}
void swap(long long *a, long long *b) {
long long temp = *a;
*a = *b;
*b = temp;
}
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
long long N, M, K;
long long ans=0, ans1=0;
scanf("%lld%lld",&N,&M);
if (N>M)
swap(&N, &M);
K= M/2;
if (N > K+1)
{
ans= sumOfPositiveIntegers(N-K, K+1);
ans*= (K+1);
if (M%2 ==0)
{
ans1= sumOfPositiveIntegers(N-K, K+1);
ans1*= K;
ans+= ans1;
}
}
else
{
ans= sumOfPositiveIntegers(1, N);
ans*= (K+1);
if (M%2 ==0)
{
ans1= sumOfPositiveIntegers(1, N);
ans1*= K;
ans+= ans1;
}
}
ans= ans%998244353;
printf("%lld\n",ans);
}
return 0;
}
Problem Link: Spread Spree Practice Coding Problem - CodeChef