Skip to content

Instantly share code, notes, and snippets.

@shubhamsgit
Created May 23, 2021 19:44
Show Gist options
  • Select an option

  • Save shubhamsgit/108248d9f016910a334c1394cc2f0671 to your computer and use it in GitHub Desktop.

Select an option

Save shubhamsgit/108248d9f016910a334c1394cc2f0671 to your computer and use it in GitHub Desktop.
#include<bits/stdc++.h>
using namespace std;
int findnum(int x1, int y1){ //function that returns the element with an index
int sum1=1;
for(int i=0;i<(x1-1);i++){
sum1=sum1+(2+i);
}
int sum2=sum1;
int j=y1-1;
int i=x1;
while(j--){
sum2=sum2+i;
i++;
}
return sum2;
}
int main()
{
int tcase;
cin>>tcase;
while(tcase--){
int x1,x2,y1,y2;
cin>>x1>>y1>>x2>>y2;
int sumf=findnum(x1,y1);
while(x1<x2){ //going down
x1++;
sumf+=findnum(x1,y1);
}
while(y1<y2){ //going right
y1++;
sumf+=findnum(x1,y1);
}
cout<<sumf<<endl;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment