QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#179485 | #5503. Euclidean Algorithm | real_sigma_team | TL | 0ms | 3572kb | C++20 | 1.8kb | 2023-09-14 21:45:38 | 2023-09-14 21:45:38 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
using ll = long long;
const int N = 3e5 + 5;
ll get_ans(ll n) {
ll ans = 0;
for (ll x = 1; x * x * x <= n; x++) {
if (x * (x * x + 1) <= n) {
ans++;
// cout << "1 " << x << ' ' << x << ' ' << x << '\n';
}
if (x * x + 1 <= n) {
ans += max<ll>(0, n / (x * x + 1) - x);
/* for (int i = x + 1; i <= n / (x * x + 1); i++) {
cout << "2 " << i << ' ' << x << ' ' << x << '\n';
}*/
}
for (ll y = x + 1; x * y + 1 <= n; y++) {
ans += max<ll>(0, (n / (x * y + 1) - (x - 1))) * 2;
/* for (int i = x + 1; i <= n / (x * y + 1); i++) {
cout << "3 " << i << ' ' << x << ' ' << y << '\n';
cout << "3 " << i << ' ' << y << ' ' << x << '\n';
}*/
}
ll need = (n - x) / x;
for (ll y = x + 1; y * y <= need; y++) {
ans += max<ll>(0, need / y - y) * 2;
/* for (int i = y + 1; i <= need / y; i++) {
cout << "4 " << x << ' ' << y << ' ' << i << '\n';
cout << "4 " << x << ' ' << i << ' ' << y << '\n';
}*/
if (y * y <= need) {
//cout << "5 " << x << ' ' << y << ' ' << y << '\n';
ans++;
}
}
}
return ans;
}
void solve() {
ll n;
cin >> n;
cout << get_ans(n) << '\n';
}
int main() {
#ifndef LOCAL
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
#else
freopen("input.txt", "r", stdin);
#endif
int t;
cin >> t;
while (t--)
solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3572kb
input:
3 2 5 14
output:
1 9 62
result:
ok 3 lines
Test #2:
score: -100
Time Limit Exceeded
input:
3 29107867360 65171672278 41641960535