Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <unordered_map>
- #include <boost/chrono.hpp>
- using namespace std;
- int main() {
- // boost:chrono::steady_clock::time_point
- boost::chrono::steady_clock::time_point start_time = boost::chrono::steady_clock::now();
- unordered_map<int, int> square_lookup;
- for(int i=0; i<= 1500; i++) {
- square_lookup[i*i] = i ;
- }
- auto end_time = boost::chrono::steady_clock::now();
- cout << "Lookup gen time " << (end_time - start_time) << endl;
- unordered_map<int, int> occurences;
- for(int i = 0; i <= 1000; i++) {
- for(int j = i; j <= 1000; j++) {
- int result = square_lookup[(i*i) + (j*j)];
- if(result) {
- int perimeter = i + j + result;
- if(perimeter <= 1000) {
- occurences[perimeter] += 1;
- }
- }
- }
- }
- int current_max_count = 0;
- int current_max = 0;
- for(auto it = occurences.begin(); it != occurences.end(); it++) {
- if(it->second > current_max_count) {
- current_max_count = it->second;
- current_max = it->first;
- }
- // cout << it->first << " : " << it->second << endl;
- }
- end_time = boost::chrono::steady_clock::now();
- cout << "C++: Result: " << current_max << " : Time: " << end_time - start_time << endl << endl;;
- }
Advertisement
Add Comment
Please, Sign In to add comment