QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#78355#5503. Euclidean AlgorithmdnialhTL 17853ms5312kbC++202.8kb2023-02-18 04:02:212023-02-18 04:03:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-18 04:03:04]
  • 评测
  • 测评结果:TL
  • 用时:17853ms
  • 内存:5312kb
  • [2023-02-18 04:02:21]
  • 提交

answer

#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

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

#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) v.begin(), v.end()
#define sz(v) (int)v.size()
#define sq(a) ((a)*(a))

#define MOO(i,a,b) for (int i=a; i<b; i++)
#define M00(i,a) for (int i=0; i<a; i++)
#define MOOd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define M00d(i,a) for (int i = (a)-1; i >= 0; i--)

#define per(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a,b) for (int i=a; i<b; i++)

#define FOR(i,a,b) for (int i=a; i<b; i++)
#define F0R(i,a) for (int i=0; i<a; i++)
#define ROF(i,a,b) for (int i = (b)-1; i >= a; i--)
#define R0F(i,a) for (int i = (a)-1; i >= 0; i--)

#define FAST ios::sync_with_stdio(0); cin.tie(0);
#define finish(x) return cout << x << endl, 0;
#define dbg(x) cerr << ">>> " << #x << " = " << x << endl;
#define _<< " _ " <<

#define ll long long

template<class T> bool ckmin(T&a, T&b) { bool B = a > b; a = min(a,b); return B; }
template<class T> bool ckmax(T&a, T&b) { bool B = a < b; a = max(a,b); return B; }

typedef long double ld;
typedef pair<int,int> pi;
typedef pair<ld,ld> pld;
typedef complex<ld> cd;

typedef vector<int> vi;
typedef vector<ld> vld;
typedef vector<vector<int>> vvi;

const ld PI = acos(-1.0);
const ld EPS = 1e-7;
const int MOD = 998244353;

const int MX = 500000;
uint32_t ic[MX];

uint32_t innerpre(int x){
  assert (x > 0);

  uint32_t out = 0;
  uint32_t curr = 1;
  
  while (curr * curr < x){
      uint32_t val = (x - 1) / curr;
      out += val;
      curr ++;
  }

  while (curr <= x - 1){
    uint32_t val = (x - 1) / curr;
    uint32_t last = (x - 1) / val;

    out += val * (last - curr + 1);
    curr = last + 1;
  }

  return out;
}

ll inner(ll x){
  assert (x > 0);
  
  if (x < MX){
      return ic[x];
  }

  ll out = 0;
  ll curr = 1;

  while (curr * curr < x){
      ll val = (x - 1) / curr;
      out += val;
      curr ++;
  }

  while (curr <= x - 1){
    ll val = (x - 1) / curr;
    ll last = (x - 1) / val;

    out += val * (last - curr + 1);
    curr = last + 1;
  }

  return out;
}

ll solve(ll n){
  assert (n > 0);

  ll out = 0;
  ll curr = 1;
  
  while (curr * curr < n){
      ll val = n / curr;
      out += inner(val);
      curr ++;
  }

  while (curr <= n){
    ll val = (n) / curr;
    ll last = n / val;

    out += inner(val) * (last - curr + 1);
    curr = last + 1;
  }

  return out;
}

int32_t main() { FAST

  FOR(i, 1, MX){
      ic[i] = innerpre(i);
  }
  
  //cout << inner(1000000) << endl;

  int z;
  cin >> z;

  F0R(i, z){
    ll n;
    cin >> n;
    ll u = solve(n);

    cout << u << '\n';
  }
  
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 4427ms
memory: 5312kb

input:

3
2
5
14

output:

1
9
62

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 17853ms
memory: 5308kb

input:

3
29107867360
65171672278
41641960535

output:

8921593237533
21300450379732
13136180138425

result:

ok 3 lines

Test #3:

score: -100
Time Limit Exceeded

input:

3
90076809172
100000000000
99913139559

output:


result: