結果
| 問題 |
No.2829 GCD Divination
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2024-12-11 21:26:08 |
| 言語 | C++23 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
AC
|
| 実行時間 | 2 ms / 2,000 ms |
| コード長 | 759 bytes |
| コンパイル時間 | 3,007 ms |
| コンパイル使用メモリ | 247,384 KB |
| 実行使用メモリ | 5,248 KB |
| 最終ジャッジ日時 | 2024-12-11 21:26:14 |
| 合計ジャッジ時間 | 4,919 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| other | AC * 35 |
ソースコード
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
vector<int> factorize(int n) {
vector<int> res;
for (int i = 2; i*i <= n; ++i) {
if (n%i != 0) continue;
res.push_back(i);
while (n%i == 0) n /= i;
}
if (n != 1) res.push_back(n);
return res;
}
int main() {
int n;
cin >> n;
auto fs = factorize(n);
int m = fs.size();
int m2 = 1<<m;
double ans = 1;
for (int s = 1; s < m2; ++s) {
int d = 1;
rep(i, m) if (s>>i&1) d *= fs[i];
int cnt = n/d;
double now = cnt*1./(n-cnt);
if (__builtin_parity(s)) ans += now;
else ans -= now;
}
printf("%.10f\n", ans);
return 0;
}