solution.cpp 859 字节
Newer Older
每日一练社区's avatar
每日一练社区 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
#include <bits/stdc++.h>
using namespace std;
int main()
{

    for (long long i = 100000; i < 1000000; i++)
    {
        //i要用longlong,不然相乘会溢出
        set<int> s1, s2;
        int t1 = i;
        while (t1)
        {
            s1.insert(t1 % 10);
            t1 /= 10;
        }
        long long t2 = i * i;
        if (s1.size() == 6)
        {
            while (t2)
            {
                s2.insert(t2 % 10);
                t2 /= 10;
            }
            bool flag = 1;
            for (auto it : s1)
            {
                if (s2.find(it) != s2.end())
                {
                    flag = 0;
                    break;
                }
            }
            if (flag == 1)
                cout << i << ' ' << i * i << endl;
        }
        s1.clear();
        s2.clear();
    }

    return 0;
}