The cube, 41063625 (3453), can be permuted to produce, and other cubes:56623104 (3843) and 66430125 (4053). In fact, 41063625 is the smallest cube which have exactly three permutations of its digits which was also cube.
Find the smallest cube for which exactly five permutations of its digits is cube.
#include <iostream> #include <map> #include <vector>using namespace std;vector<int> sh ( unsigned long long N) {vector<int>res (ten); 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 (ten); tmp= sh (n);//cout << i << endl;if (mp.find (tmp) = = Mp.end ()) mp[tmp] = {i}; Elsemp[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;}
There are two sets of results, the result being the smallest one.
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Project Euler:problem Cubic permutations