The problem is to find the no. of 3x3 matrices of perfect squares....like:

121

256

169

whose transpose is same as the original..

The solution I came up with is:

1.Make an array of vectors of the sq nos within the range..(such that..each array contains a vector of the no.s beginning with its(the array's) index...)

2.Iterate over the square nos in the range

--1.Put the current no. as the first row.

--2.Iterate over the set(that array of vectors!) which begins with the middle digit of the first row.

----1.Put the current no. as the 2nd row.

----2..Iterate over the set which begins with the 3rd digit of the first row.

------1.Put the no as the 3rd row.

------2.If the 3rd digit of the 2nd row == 2nd digit of the 3rd row.

----------<You have found one of such a matrix>

------3.Continue.

3.Output ..etc etc..

_____________________

It works...as expected..and finds out all of the matrices..

..But the 2 nested loops feels very ..err...clumsy ...take a look..

..... I figured out(not having a good idea about the mathematical aspects of algorithms..)..that this is better than iterating over all(more than 20!) the possible matrices..Code:for(c=10;c*c<1000;c++) { temp.v1=itotr(c*c); for(VI it1=st[temp.v1[1]].begin();it1!=st[temp.v1[1]].end();it1++) { temp.v2=*it1; for(VI it2=st[temp.v1[2]].begin();it2!=st[temp.v1[2]].end();it2++) { temp.v3=*it2; if(temp.v2[2]==temp.v3[1]) { mc++; storage.push_back(temp); } } } }

IS there a better and simpler way of doing this...??