QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#76854#5503. Euclidean AlgorithmLYC_musicML 0ms0kbC++141.2kb2023-02-12 13:32:452023-02-12 13:32:48

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-12 13:32:48]
  • 评测
  • 测评结果:ML
  • 用时:0ms
  • 内存:0kb
  • [2023-02-12 13:32:45]
  • 提交

answer

#include <bits/stdc++.h>
#define poly vector<int>
#define IOS ios::sync_with_stdio(false)
#define ll long long
#define mp make_pair
#define mt make_tuple
#define pa pair<int, int>
#define fi first
#define se second
#define inf 1e18
#define mod 998244353
// #define int ll
#define N 1005
using namespace std;
const int B=2000000;
ll n, ans;
int g[B+5];
inline ll query(ll X)
{
    if (X <= B)
        return g[X];
    ll Y = 0;
    for (ll L = 1; L < X; L++)
    {
        ll R = X / (X / L);
        Y += (R - L + 1) * ((X / L) - 1);
        L = R;
    }
    return Y;
}
void BellaKira()
{
    cin >> n;
    ans = 0;
    for (ll l = 1; l < n; l++)
    {
        ll r = n / (n / l);
        r = min(r, n - 1);
        ll X = ((n / l) - 1);
        ll Y = query(X);
        ans += Y * (r - l + 1);
        l = r;
    }
    ans+=query(n);
    cout << ans << '\n';
}
signed main()
{
    IOS;
    cin.tie(0);
    ll T = 1;
    cin >> T;
    for (ll X = 1; X <= B; ++X)
    {
    	for (ll Y=X+X;Y<=B;Y+=X)
    		g[Y]+=1;
    	g[X]+=g[X-1];
    }
    // cout<<g[B]<<'\n';
    // return 0;
    while (T--)
    {
        BellaKira();
    }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Memory Limit Exceeded

input:

3
2
5
14

output:


result: