QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#222717#5503. Euclidean Algorithmucup-team859#WA 331ms4432kbC++233.6kb2023-10-21 18:04:102023-10-21 18:04:11

Judging History

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

  • [2023-10-21 18:04:11]
  • 评测
  • 测评结果:WA
  • 用时:331ms
  • 内存:4432kb
  • [2023-10-21 18:04:10]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using namespace chrono;

using ll = long long;
using ull = unsigned long long;

string to_string(const string &s) {
  return '"' + s + '"';
}

string to_string(bool b) {
  return b ? "true" : "false";
}

template <typename A, typename B>
string to_string(const pair<A, B> &p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename T>
string to_string(const T &v) {
  string s = "{";
  bool first = true;
  for (const auto &it : v) {
    if (!first)
      s += ", ";
    else
      first = false;
    s += to_string(it);
  }
  return s += "}";
}

void debug_out() {
  cerr << endl;
}

template <typename T, typename... Args>
void debug_out(const T &first, const Args&... rest) {
  cerr << to_string(first) << " ";
  debug_out(rest...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

auto startTime = high_resolution_clock::now();
int get_time() {
  auto stopTime = chrono::high_resolution_clock::now();
  auto duration = duration_cast<milliseconds>(stopTime - startTime);
  return duration.count(); // in ms
}

int generate(int x, int y) {
  int gc = __gcd(x, y);

  map<int, int> f;
  f[x] = f[y] = 1;
  vector<int> v;
  v.push_back(x);
  v.push_back(y);

  int steps = 100, last = 100;
  int lim = 10 * max(x, y);
  while (last > 0) {
    --last;
    int x = v[rng() % v.size()]; 
    int y = v[rng() % v.size()]; 
    if (x == y)
      continue;

    if (2LL * x - y <= lim && 2LL * x - y >= gc && !f.count(2LL * x - y)) {
      v.push_back(2LL * x - y);
      last = 100;
      f[2LL * x - y] = 1;
    }

    swap(x, y);
    if (2LL * x - y <= lim && 2LL * x - y >= gc && !f.count(2LL * x - y)) {
      v.push_back(2LL * x - y);
      last = 100;
      f[2LL * x - y] = 1;
    }

    if (f.count(gc))
      return 1;

  }

  return f.count(gc) > 0;
}

int nrdiv(int x) {
  int nr = 0;
  for (int i = 1; i <= x; ++i) {
    if (x % i == 0)
      ++nr;
  }

  return nr;
}

const int sz = 316250;
vector <int> maxPrim;
void computeCiur() {
    maxPrim.resize(sz + 1);
    for (int i = 1; i <= sz; ++i)
      maxPrim[i] = 0;
    for (int i = 2; i <= sz; i++) {
        if (maxPrim[i] != 0) {
            continue;
        }
        for (int j = i; j <= sz; j += i) {
            maxPrim[j] = i;
        }
    }
}

int nrdiv_optim(int n) {
    if (n == 0)
      return 0;
    int frecv = 0, currPrim = -1, ans = 1;
    while (n != 1) {
        if (maxPrim[n] != currPrim) {
            ans *= (frecv + 1);
            frecv = 0;
        }
        currPrim = maxPrim[n];
        frecv++;
        n /= maxPrim[n];
    }
    ans *= (frecv + 1);
    return ans;
}

ll get_div_interval(int n) {
  int r = sqrt(n); 
  ll sum = 0;
  int last = n;
  for (int j = 1; j <= r; ++j) {
    int r = n / j;
    int l = n / (j + 1) + 1;

    last = l;

//    cout << n << " " << l << " " << r << " " << j << endl;
    sum += 1LL * j * (r - l + 1);

  }

  for (int j = 1; j < last; ++j)
    sum += n / j;

  return sum;
}

void solve() {
  int n;
  cin >> n;

  ll sum = 0;
  int r = sqrt(n);
  for (int i = 1; i <= r; ++i) {
    sum += get_div_interval(n / i - 1);
  }

  for (int i = 1; i <= r; ++i) {
    sum += nrdiv_optim(i - 1) * (n / i - r);
  }
  
  cout << sum << endl;
}

int main() {
  cin.tie(NULL);
  ios_base::sync_with_stdio(false);

  computeCiur();
  int t = 1;
  cin >> t;
  while (t--)
    solve();

  return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 4352kb

input:

3
2
5
14

output:

1
9
62

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 331ms
memory: 4432kb

input:

3
29107867360
65171672278
41641960535

output:

526529808500
526529808500
526529808500

result:

wrong answer 1st lines differ - expected: '8921593237533', found: '526529808500'