結果
| 問題 |
No.1022 Power Equation
|
| コンテスト | |
| ユーザー |
kyort0n
|
| 提出日時 | 2020-04-10 21:52:35 |
| 言語 | C++14 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 1,143 ms / 2,000 ms |
| コード長 | 1,823 bytes |
| コンパイル時間 | 1,711 ms |
| コンパイル使用メモリ | 169,044 KB |
| 実行使用メモリ | 5,376 KB |
| 最終ジャッジ日時 | 2024-09-15 20:13:44 |
| 合計ジャッジ時間 | 6,804 ms |
|
ジャッジサーバーID (参考情報) |
judge1 / judge4 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 1 |
| other | AC * 8 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
if(a < b) {
a = b;
return true;
}
return false;
}
template<class T>
inline bool chmin(T &a, T b) {
if(a > b) {
a = b;
return true;
}
return false;
}
const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
//const ll mod = 1000000007;
bool ok(ll x) {
vector<ll> v;
for(ll i = 2; i * i <= x; i++) {
if(x % i == 0) {
v.push_back(0);
while(x % i == 0) {
v.back()++;
x /= i;
}
}
}
//if(x != 1) v.push_back(1);
if(x != 1) return true;
ll g = 0;
for(auto val : v) {
g = __gcd(val, g);
}
return g == 1;
}
ll N;
ll g(ll x) {
ll ret = 0;
for(ll i = 1; i <= x; i++) {
for(ll j = 1; j <= x; j++) {
ll g = __gcd(i, j);
ll M = max(i, j);
ll m = min(i, j);
M /= g;
m /= g;
ret += N / M;
}
}
return ret;
}
void solve() {
cin >> N;
ll ans = N * N;
ll Total = N - 1;
for(ll i = 2; i * i <= N; i++) {
if(ok(i)) {
//cerr << i << endl;
ll num = 0;
for(ll j = i; j <= N; j *= i) {
num++;
}
Total -= num;
//cerr << i << " " << num << " " << g(num) << endl;
ans += g(num);
}
}
//cerr << Total << endl;
ans += Total * N;
cout << ans << endl;
}
int main() {
//cout.precision(10);
cin.tie(0);
ios::sync_with_stdio(false);
ll T;
cin >> T;
while(T--) solve();
return 0;
}
kyort0n