QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#111719 | #5503. Euclidean Algorithm | xaphoenix# | TL | 19629ms | 7404kb | C++14 | 1.6kb | 2023-06-07 23:23:52 | 2023-06-07 23:23:57 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define LC k<<1
#define RC k<<1|1
#define IO cin.sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define rep(i,a,n) for (int i = a; i < n; i++)
#define repn(i,a,n) for (int i = a; i <= n; i++)
#define per(i,a,n) for (int i = (n) - 1; i >= a; i--)
#define pern(i,a,n) for (int i = n; i >= a; i--)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ull;
typedef pair<int, int> PII;
typedef pair<int, LL> PIL;
typedef pair<LL, int> PLI;
typedef pair<double, double> PDD;
typedef pair<ull, ull> PUU;
typedef pair<LL, LL> PLL;
const int N = 510000;
const int M = 1100000;
const int mod = 1e9+7;
const int inf = (int)1e9;
const LL INF = 1e18;
const double eps = 1e-9;
mt19937_64 Rand((unsigned long long)new char);
#define rand Rand
LL f[N];
LL cal(LL x) {
if (x < N) return f[x];
LL l = 1, r, res = 0;
while (l <= x) {
r = x / (x / l);
res += (x / l) * (r - l + 1);
l = r + 1;
}
return res;
}
int T;
LL n;
int main() {
IO;
rep(i, 1, N) {
rep(j, 1, N) {
if (i * j >= N) break;
f[i * j] += 1;
}
}
rep(i, 1, N) f[i] += f[i - 1];
cin >> T;
// T = 3033;
while (T--) {
cin >> n;
// if (T <= 2) n = (LL)1e11;
// else if (T <= 32) n = inf;
// else n = 1000000;
LL l = 1, r = n, ans = 0;
while (l <= n) {
r = n / (n / l);
ans += cal(n / l - 1) * (r - l + 1);
l = r + 1;
}
cout << ans << "\n";
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 13ms
memory: 7404kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: 0
Accepted
time: 19629ms
memory: 7372kb
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