Submission #772905


Source Code Expand

Copy
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
int main() {
  int n, x, y, k, tmp, m = INT_MAX, lim = 10000;
  cin >> n;
  x = y = sqrt(n);
  if (x * y == n) {
    cout << 0 << endl;
    return 0;
  } else {
    for (int i = 0; i < lim && x > 0 && y > 0; ++i) {
      k = n - x * y;
      if (k >= 0) {
        tmp = x - y + k;
        if (tmp < m) {
          m = tmp;
          if (m == 1) i = lim;
        }
      }
      i % 2 == 0 ? x++ : y--;
    }
    cout << m << endl;
  }
  return 0;
}

Submission Info

Submission Time
Task B - □□□□□
User yka
Language C++14 (GCC 5.4.1)
Score 0
Code Size 593 Byte
Status

Compile Error

./Main.cpp: In function ‘int main()’:
./Main.cpp:8:28: error: ‘INT_MAX’ was not declared in this scope
   int n, x, y, k, tmp, m = INT_MAX, lim = 10000;
                            ^
./Main.cpp:15:25: error: ‘lim’ was not declared in this scope
     for (int i = 0; i < lim && x > 0 && y > 0; ++i) {
                         ^