Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <math.h>
- #include <numeric>
- #include <fstream>
- #include <string.h>
- #include <stdlib.h>
- using namespace std;
- /*
- Find the sum of the first thirty golden nuggets.
- */
- long long f(int l) {
- int i;
- long long a, r, x, y;
- //Init
- r = 0;
- a = 2; // First golden nugget
- x = -1;
- y = -1;
- for(i = 0; i < l / 2; i++) {
- // Add golden nugget to answer
- r += a;
- // Calculate next golden nugget
- a = (a + a) - x;
- // Add golden nugget to answer
- r += a;
- // Calculate next golden nugget
- a = (a * 4) - y;
- // Update
- x = (y - x) / 2;
- y = 14 + (19 * x) - (y + y);
- }
- return r;
- }
- int main() {
- cout << "Result = " << f(30) << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement