Advertisement
Guest User

Untitled

a guest
Oct 8th, 2015
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.61 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int n;
  8.     long sum = 4;
  9.  
  10.     bool base = true;
  11.     int need = 0;
  12.     int counter = 0;
  13.     bool second = true;
  14.  
  15.     cin >> n;
  16.  
  17.     for (int i = 2; i <= n; ++i)
  18.     {
  19.         if (i == 2)
  20.         {
  21.             sum += 3;
  22.         }
  23.         else
  24.         {
  25.             if (base)
  26.             {
  27.                 sum += 3;
  28.                 if (second)
  29.                 {
  30.                     need++;
  31.                     counter = 0;
  32.                     second = false;
  33.                 }
  34.                 else
  35.                 {
  36.                     second = true;
  37.                     counter = 0;
  38.                 }
  39.                 base = false;
  40.             }
  41.             else
  42.             {
  43.                 sum += 2;
  44.                 counter++;
  45.                 if (counter == need)
  46.                     base = true;
  47.             }
  48.         }
  49.  
  50.     }
  51.  
  52.     cout << sum << endl;
  53.    
  54.     return 0;
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement