Advertisement
Guest User

100knyck

a guest
Feb 10th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.21 KB | None | 0 0
  1. #include <iostream>
  2. #include <chrono>
  3. #include <unordered_set>
  4.  
  5. using namespace std;
  6. using std::chrono::nanoseconds;
  7. using std::chrono::duration_cast;
  8. using std::chrono::system_clock;
  9.  
  10. bool check(int n) {
  11.     int digits = 0; int count = 0; int tmp;
  12.  
  13.     for (; n > 0; n /= 10, ++count)
  14.     {
  15.         if ((tmp = digits) == (digits |= 1 << (n - ((n / 10) * 10) - 1)))
  16.             return false;
  17.     }
  18.  
  19.     return digits == (1 << count) - 1;
  20. }
  21.  
  22. int main() {
  23.     const auto start = system_clock::now();
  24.     int s = 0;
  25.  
  26.     for (int asdf = 0; asdf < 1000; asdf++) {
  27.  
  28.     unordered_set<int> myset;
  29.     for (int a = 4; a < 49; a++) {
  30.         for (int b = 157; b < 7860/a; b++) {
  31.            
  32.             int c = a*b;
  33.             int f1 = 1000;
  34.  
  35.             if (c >= 10000) {
  36.                 f1 = 100000;
  37.             } else if (c >= 1000) {
  38.                 f1 = 10000;
  39.             }
  40.             int f2 = (b >= 1000 ? 10000*f1 : 1000*f1);
  41.             int n = f2*a+f1*b+c;
  42.             if (n >= 123456789 && check(n)) {
  43.                 if (myset.find(c) == myset.end()) {
  44.                     s += c;
  45.                     myset.insert(c);
  46.                 }
  47.             }
  48.         }
  49.     }
  50.     }
  51.     const auto stop = system_clock::now();
  52.     const auto d_actual = duration_cast<nanoseconds>(stop - start).count();
  53.     const auto d_new = d_actual/1000000;
  54.     cout << s/1000 << endl;
  55.     cout << d_new << endl;
  56.    
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement