本帖最后由 永恒的蓝色梦想 于 2021-2-17 22:05 编辑
C++ 3ms#include<iostream>
#include<limits>
#include<unordered_map>
size_t hash_permutation(unsigned long long n) {
constexpr unsigned long long add[] = { 1ull, 1ull << 5, 1ull << 10, 1ull << 15, 1ull << 20, 1ull << 25, 1ull << 30, 1ull << 35, 1ull << 40, 1ull << 45 };
constexpr unsigned short ENLARGE = (unsigned long long)(-1) / (0b10100ull << (9 * 5));
unsigned long long t, result = 0;
while (n) {
t = n;
n /= 10;
result += add[t - n * 10];
}
return result * ENLARGE;
}
struct MapVal {
unsigned long long min;
unsigned char count = 0;
};
int main() {
using namespace std;
ios::sync_with_stdio(false);
unordered_map<size_t, MapVal> counter;
unsigned long long n, cube_of_n;
MapVal* ptr;
for (n = 1; n < 10000; n++) {
cube_of_n = n * n * n;
ptr = &counter[hash_permutation(cube_of_n)];
if (!(ptr->count)) {
ptr->min = cube_of_n;
}
ptr->count++;
}
n = numeric_limits<unsigned long long>::max();
for (auto& i : counter) {
if (i.second.count == 5) {
if (i.second.min < n) {
n = i.second.min;
}
}
}
cout << n << endl;
return 0;
}
|