#include<iostream> #include<vector> using namespace std; bool isNumber(vector<int> v1, vector<int> v2) { for (int i = 0; i < v1.size(); i++) { for (int j = 0; j < v2.size(); j++) { if (v1[i] == v2[j]) return false; } } return true; } bool isSingle(vector<int>v) { for (int i = 1; i < v.size(); i++) { for (int j = 0; j < i; j++) { if (v[i] == v[j]) return false; } } return true; } int main() { for (int i = 100; i <= 999; i++) { vector<int> v1, v2; int k = i * i; int y = i; while (k != 0) { int j = k % 10; v1.push_back(j); k /= 10; } while (y != 0) { int u = y % 10; v2.push_back(u); y /= 10; } if (isNumber(v1, v2) && isSingle(v1) && isSingle(v2)) { cout << i << " "; } } }
输出结果为:209,259,567,807,854