Guest User

Untitled

a guest
Feb 7th, 2015
345
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.37 KB | None | 0 0
  1. #include <iostream>
  2. #include <unordered_map>
  3. #include <boost/chrono.hpp>
  4.  
  5.  
  6. using namespace std;
  7.  
  8. int main() {
  9.     // boost:chrono::steady_clock::time_point
  10.     boost::chrono::steady_clock::time_point start_time = boost::chrono::steady_clock::now();
  11.     unordered_map<int, int> square_lookup;
  12.     for(int i=0; i<= 1500; i++) {
  13.         square_lookup[i*i] = i ;
  14.     }
  15.     auto end_time = boost::chrono::steady_clock::now();
  16.  
  17.     cout << "Lookup gen time " << (end_time - start_time) << endl;
  18.  
  19.     unordered_map<int, int> occurences;
  20.  
  21.     for(int i = 0; i <= 1000; i++) {
  22.         for(int j = i; j <= 1000; j++) {
  23.             int result = square_lookup[(i*i) + (j*j)];
  24.  
  25.             if(result)  {
  26.                 int perimeter = i + j + result;
  27.                 if(perimeter <= 1000) {
  28.                     occurences[perimeter] += 1;
  29.                 }
  30.             }
  31.         }
  32.     }
  33.  
  34.     int current_max_count = 0;
  35.     int current_max = 0;
  36.     for(auto it = occurences.begin(); it != occurences.end(); it++) {
  37.         if(it->second > current_max_count) {
  38.             current_max_count = it->second;
  39.             current_max = it->first;
  40.         }
  41. //        cout << it->first << " : " << it->second << endl;
  42.     }
  43.     end_time = boost::chrono::steady_clock::now();
  44.     cout << "C++: Result: " << current_max << " : Time: " << end_time - start_time << endl << endl;;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment