SHARE
TWEET

Untitled

a guest Mar 22nd, 2018 123 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <math.h>
  5. #include <numeric>
  6. #include <fstream>
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. using namespace std;
  11.  
  12. /*
  13.     Find the sum of the first thirty golden nuggets.
  14. */
  15.  
  16. long long f(int l) {
  17.     int i;
  18.     long long a, r, x, y;
  19.    
  20.     //Init
  21.     r = 0;
  22.     a = 2; // First golden nugget
  23.     x = -1;
  24.     y = -1;
  25.    
  26.     for(i = 0; i < l / 2; i++) {
  27.         // Add golden nugget to answer
  28.         r += a;
  29.        
  30.         // Calculate next golden nugget
  31.         a = (a + a) - x;
  32.        
  33.         // Add golden nugget to answer
  34.         r += a;
  35.        
  36.         // Calculate next golden nugget
  37.         a = (a * 4) - y;
  38.        
  39.         // Update
  40.         x = (y - x) / 2;
  41.         y = 14 + (19 * x) - (y + y);
  42.     }
  43.    
  44.     return r;
  45. }
  46.  
  47. int main() {
  48.     cout << "Result = " << f(30) << endl;
  49.    
  50.     return 0;
  51. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top