Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<iostream>
- #include<vector>
- using namespace std;
- int fr(int k){
- for (long long i = k; i >= 0; --i){
- if (i*i <= k) return i;
- }
- }
- int main(){
- int n; cin >> n; int f = fr(n); //cout << fr(n) << endl;
- if (n - f*f == 0) cout << 4*f;
- else if (n - f*f == 1) cout << 4*f + 2;
- else if (n - f*f > 1 && n - f*f < f + 1) cout << 4*f + 2;
- else if (n - f*f == f + 1) cout << 4*f + 4;
- else if (n - f*f > f + 1 && n - f*f <= 2*f + 1) cout << 4*f + 4;
- else if (n - f*f == 2*f + 2) cout << 4*f + 6;
- else if (n - f*f > 2*f + 2 && n - f*f <= 3*f + 2) cout << 4*f + 6;
- else if (n - f*f == 3*f + 3) cout << 4*f + 8;
- else cout << 4*f + 8;
- }
Advertisement
Add Comment
Please, Sign In to add comment