Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int main()
- {
- int n;
- long sum = 4;
- bool base = true;
- int need = 0;
- int counter = 0;
- bool second = true;
- cin >> n;
- for (int i = 2; i <= n; ++i)
- {
- if (i == 2)
- {
- sum += 3;
- }
- else
- {
- if (base)
- {
- sum += 3;
- if (second)
- {
- need++;
- counter = 0;
- second = false;
- }
- else
- {
- second = true;
- counter = 0;
- }
- base = false;
- }
- else
- {
- sum += 2;
- counter++;
- if (counter == need)
- base = true;
- }
- }
- }
- cout << sum << endl;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement