Created
August 22, 2013 19:03
-
-
Save MasterAlish/6311379 to your computer and use it in GitHub Desktop.
Solution for "sunloverz / gist:6309925" on c++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
class RectangularGrid{ | |
public: | |
long long countRectangles(int n, int m){ | |
long long sum=0; | |
for(int i_n=1; i_n<=n; i_n++) | |
for(int i_m=1; i_m<=m; i_m++) | |
if(i_m!=i_n) | |
sum+=(m-i_m+1)*(n-i_n+1); | |
return sum; | |
}; | |
}; | |
int main(){ | |
RectangularGrid* r = new RectangularGrid(); | |
printf("%lld",r->countRectangles(3,3)); | |
printf("%lld",r->countRectangles(2,5)); | |
printf("%lld",r->countRectangles(592,964)); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment