The cube, 41063625 (3453), can be permuted to produce two other cubes: 56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which has exactly three permutations of its digits which are also cube.
Find the smallest cube for which exactly five permutations of its digits are cube.
#include <iostream>
#include <map>
#include <vector>
using namespace std;
vector<int> sh(unsigned long long n)
{
vector<int>res(10);
while (n)
{
res[n % 10]++;
n /= 10;
}
return res;
}
int main()
{
map<vector<int>, vector<int>>mp;
for (int i = 1; i < 10000; i++)
{
unsigned long long n = i*i;
n = n*i;
vector<int>tmp(10);
tmp= sh(n);
//cout << i << endl;
if (mp.find(tmp) == mp.end())
mp[tmp] = { i };
else
mp[tmp].push_back(i);
}
map<vector<int>, vector<int>>::iterator iter;
for (iter = mp.begin(); iter != mp.end(); iter++)
{
if (iter->second.size() == 5)
{
for (int i = 0; i < 5; i++)
{
cout << iter->second[i] <<" ";
}
unsigned long long n = iter->second[0] * iter->second[0];
n = n*iter->second[0];
cout << n << endl;
}
}
system("pause");
return 0;
}
有两组结果,结果为首项最小的那个。