title: Count Distinct Non Negative Pairs X Y Satisfy Inequality Xx Yy N 2 1
signature: count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2_1 <- function(n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          72L, 
          64L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          75L, 
          69L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          92L, 
          83L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          30L, 
          30L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          45L, 
          41L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          40L, 
          37L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          81L, 
          71L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          17L, 
          17L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          81L, 
          71L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          99L, 
          86L
      )))
  
  }
  
  main()
source_py: def count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2_1(n):
      x = 0
      res = 0
      yCount = 0
      while ((yCount * yCount) < n):
          yCount = (yCount + 1)
      while (yCount != 0):
          res = (res + yCount)
          x = (x + 1)
          while ((yCount != 0) and (((x * x) + ((yCount - 1) * (yCount - 1))) >= n)):
              yCount = (yCount - 1)
      return res
source_cpp: int count_distinct_non_negative_pairs_x_y_satisfy_inequality_xx_yy_n_2_1(int n) {
    int x = 0, yCount, res = 0;
    for ( yCount = 0;
    yCount * yCount < n;
    yCount ++ );
    while ( yCount != 0 ) {
      res += yCount;
      x ++;
      while ( yCount != 0 && ( x * x + ( yCount - 1 ) * ( yCount - 1 ) >= n ) ) yCount --;
    }
    return res;
  }