結果
| 問題 |
No.1022 Power Equation
|
| コンテスト | |
| ユーザー |
TAISA_
|
| 提出日時 | 2020-04-10 22:39:48 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 6 ms / 2,000 ms |
| コード長 | 2,207 bytes |
| コンパイル時間 | 1,983 ms |
| コンパイル使用メモリ | 193,520 KB |
| 最終ジャッジ日時 | 2025-01-09 16:23:28 |
|
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
#define pb push_back
#define eb emplace_back
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using V = vector<int>;
using VL = vector<ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll MOD = 1e9 + 7;
constexpr int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
template <class T>
void chmin(T &a, T b) { a = min(a, b); }
template <class T>
void chmax(T &a, T b) { a = max(a, b); }
void ok() { cerr << "ok" << endl; }
bool so[31][31];
int main() {
cin.tie(0);
ios::sync_with_stdio(0);
int t;
cin >> t;
for (int i = 1; i <= 30; i++) {
for (int j = 1; j <= 30; j++) {
if (__gcd(i, j) == 1) {
so[i][j] = 1;
}
}
}
while (t--) {
ll n;
cin >> n;
ll res = n * n + n * (n - 1LL);
for (ll k = 2; k <= 30; k++) {
ll ok = 0, ng = n + 1;
auto check = [&](ll x) {
ll s = 1LL;
for (int i = 0; i < k; i++) {
s *= x;
if (s > n) return false;
}
return true;
};
while (ng - ok > 1LL) {
ll mid = (ok + ng) / 2LL;
if (check(mid)) {
ok = mid;
} else {
ng = mid;
}
}
ll dc = n / k;
res += dc * (ok - 1LL) * 2LL;
}
for (ll k = 2; k <= 30; k++) {
for (ll a = 2; a * a <= n; a++) {
ll s = 1;
bool f = true;
if (k >= 3) {
for (int i = 0; i < k; i++) {
s *= a;
if (s > n) f = false;
}
}
if (!f) break;
for (ll l = 2; l <= k; l++) {
if (so[k][l]) {
res += n / max(k, l);
if (k > l) {
res += n / max(k, l);
}
}
}
}
}
cout << res << '\n';
}
}
TAISA_