Project Euler:problem Cubic permutations

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.