首页 > 其他 > 详细

Project Euler:Problem 62 Cubic permutations

时间:2015-07-14 18:20:34      阅读:191      评论:0      收藏:0      [点我收藏+]

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;
}

有两组结果,结果为首项最小的那个。

版权声明:本文为博主原创文章,未经博主允许不得转载。

Project Euler:Problem 62 Cubic permutations

原文:http://blog.csdn.net/youb11/article/details/46878509

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!