12. AABB

topic:

 The outputs of all four aabb shaped like a perfect square (i.e., equal to two digits, the last two digits are equal)

 

Ideas:

List all possible combinations enumeration method, and then determines whether the number is a perfect square. 1 from the beginning and a, b from zero. 

 

Code:

#include <iostream>
#include <cmath>
using namespace std;

int main()
{
for (int a = 1; a <= 9; ++a) {
for (int b = 0; b <= 9; ++b) {
int n = a * 1100 + b * 11;
int m = floor(sqrt(n) + 0.5);
if (m*m == n) {
cout << n << endl;
}
}
}

return 0;
}

Guess you like

Origin www.cnblogs.com/Hello-Nolan/p/12111390.html