Search for a command to run...
Progressive hints first, then the full explanation and implementation when you're ready to cash out.
Review status
AI-generated and still unreviewed. Double-check the details before internalizing them.
Hints
Open only as much as you need to keep the solve alive.
This condition is multiplicative-looking because both and are controlled prime-by-prime. Stop trying random triples; look at one prime exponent at a time.
For a fixed prime , write , , and . The condition becomes
Use the lattice identity
So the equality can only hold when .
The inequality for every prime means exactly one clean thing: divides both and .
Fix . Then and can be chosen independently among multiples of from to , giving triples. Sum that over all .
The scary expression is mostly cosplay. The actual condition is just divisibility.
For each prime , write , , and . The condition becomes
Using
the left side becomes . This equals exactly when
So for every prime ,
That means divides both and . Equivalently, .
Now counting is easy. Fix . The number of choices for is the number of multiples of from to :
Same for , independently. So fixed contributes
valid triples.
Therefore the answer is
Since the total sum of over all tests is at most , a direct loop over per test case is completely fine.
Time complexity: .
Memory complexity: .
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
ll ans = 0;
for (int b = 1; b <= n; b++) {
ll cnt = n / b;
ans += cnt * cnt;
}
cout << ans << '\n';
}
return 0;
}#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void setIO() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
int main() {
setIO();
int t;
cin >> t;
while (t--) {
int n;
cin >> n;
ll ans = 0;
for (int b = 1; b <= n; b++) {
ll cnt = n / b;
ans += cnt * cnt;
}
cout << ans << '\n';
}
return 0;
}