QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#317034#8167. Yet Another Simple Math Problemhos_lyricWA 0ms3788kbC++142.0kb2024-01-28 12:23:382024-01-28 12:23:38

Judging History

你现在查看的是最新测评结果

  • [2024-01-28 12:23:38]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3788kb
  • [2024-01-28 12:23:38]
  • 提交

answer

#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;

using Int = long long;

template <class T1, class T2> ostream &operator<<(ostream &os, const pair<T1, T2> &a) { return os << "(" << a.first << ", " << a.second << ")"; };
template <class T> ostream &operator<<(ostream &os, const vector<T> &as) { const int sz = as.size(); os << "["; for (int i = 0; i < sz; ++i) { if (i >= 256) { os << ", ..."; break; } if (i > 0) { os << ", "; } os << as[i]; } return os << "]"; }
template <class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cerr << *i << " "; cerr << endl; }
template <class T> bool chmin(T &t, const T &f) { if (t > f) { t = f; return true; } return false; }
template <class T> bool chmax(T &t, const T &f) { if (t < f) { t = f; return true; } return false; }
#define COLOR(s) ("\x1b[" s "m")


/*
  x + y^2 = a
  x^2 + y = b
  
  (x'-x) + (y'^2-y^2) = 0
  (x'^2-x^2) + (y'-y) = 0
  |x'-x| = |y'^2-y^2| = |y'+y| |y'-y| > |y'-y|  if y != y'
*/

int main() {
  for (int numCases; ~scanf("%d", &numCases); ) { for (int caseId = 1; caseId <= numCases; ++caseId) {
    Int N;
    scanf("%lld", &N);
    
    Int ans = 0;
    /*
      1 <= x <= y
      x < y: weight 2
      x = y: weight 1
      
      x + y^2 <= N
      y <= sqrt(N) - 1 ==> y + y^2 <= N
    */
    const Int sqrtN = sqrt((long double)N);
    const Int R = N - sqrtN * sqrtN;
    ans += (sqrtN - 1) * (sqrtN - 1);
    ans += min(N - 1, R) * 2;
    if (sqrtN <= R) ans += 1;
    
    printf("%lld\n", ans);
  }
#ifndef LOCAL
  break;
#endif
  }
  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3788kb

input:

3
6
1
101

output:

6
0
83

result:

wrong answer 1st words differ - expected: '4', found: '6'