crowulll

Untitled

Aug 18th, 2020
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include<iostream>
  2. #include<vector>
  3. using namespace std;
  4. int fr(int k){
  5.     for (long long i = k; i >= 0; --i){
  6.         if (i*i <= k) return i;
  7.     }
  8. }
  9. int main(){
  10.     int n; cin >> n; int f = fr(n); //cout << fr(n) << endl;
  11.     if (n - f*f == 0) cout << 4*f;
  12.     else if (n - f*f == 1) cout << 4*f + 2;
  13.     else if (n - f*f > 1 && n - f*f < f + 1) cout << 4*f + 2;
  14.     else if (n - f*f == f + 1) cout << 4*f + 4;
  15.     else if (n - f*f > f + 1 && n - f*f <= 2*f + 1) cout << 4*f + 4;
  16.     else if (n - f*f == 2*f + 2) cout << 4*f + 6;
  17.     else if (n - f*f > 2*f + 2 && n - f*f <= 3*f + 2) cout << 4*f + 6;
  18.     else if (n - f*f == 3*f + 3) cout << 4*f + 8;
  19.     else cout << 4*f + 8;
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment