Finished 62 in a jiffy, wasn't hard when using a sorted list to keep track of the found cubes
This commit is contained in:
48
projecteuler/062/main.cpp
Normal file
48
projecteuler/062/main.cpp
Normal file
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
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 <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
typedef long long ll;
|
||||
|
||||
int main(){
|
||||
|
||||
cout << "Hello this is Patrick" << endl;
|
||||
auto start = chrono::high_resolution_clock::now();
|
||||
|
||||
map<string, int> occs;
|
||||
map<string, vector<ll>> cubes;
|
||||
|
||||
int n = 1;
|
||||
ll cube, result;
|
||||
string s;
|
||||
|
||||
while(true){
|
||||
cube = pow(n, 3);
|
||||
|
||||
s = to_string(cube);
|
||||
sort(s.begin(), s.end());
|
||||
|
||||
occs[s]++;
|
||||
cubes[s].push_back(cube);
|
||||
|
||||
if(occs[s] == 5){
|
||||
result = cubes[s].front();
|
||||
break;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
|
||||
cout << result << endl;
|
||||
|
||||
auto duration = chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start);
|
||||
cout << (float)duration.count()/1000 << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user