Project Euler:Problem 62 Cubic permutations

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

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值