結果

問題 No.1271 初めての級数
ユーザー fumuumuffumuumuf
提出日時 2020-11-02 11:49:36
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 2,771 bytes
コンパイル時間 1,550 ms
コンパイル使用メモリ 170,356 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-29 11:45:46
合計ジャッジ時間 6,554 ms
ジャッジサーバーID
(参考情報)
judge14 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 WA -
testcase_01 AC 302 ms
4,380 KB
testcase_02 AC 302 ms
4,380 KB
testcase_03 AC 302 ms
4,376 KB
testcase_04 AC 302 ms
4,376 KB
testcase_05 AC 302 ms
4,376 KB
testcase_06 AC 302 ms
4,380 KB
testcase_07 AC 302 ms
4,380 KB
testcase_08 AC 303 ms
4,376 KB
testcase_09 AC 303 ms
4,380 KB
testcase_10 AC 303 ms
4,376 KB
testcase_11 AC 303 ms
4,376 KB
testcase_12 AC 301 ms
4,376 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#pragma region Region_1

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define srep(i, s, t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(), a.end()
#define rrng(a) a.rbegin(), a.rend()
using ll = long long;
using P = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VP = vector<P>;
#define MOD 1000000007
const int INF = 1e9 + 10;

template <class T, class C>
void chmax(T& a, C b) {
    if (a <= b) a = b;
}
template <class T, class C>
void chmin(T& a, C b) {
    if (a >= b) a = b;
}

// const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
// const int dx[]{0, 1, 0, -1}, dy[]{1, 0, -1, 0};

template <class T>
T sum(const vector<T>& v) {
    T res = 0;
    for (size_t i = 0; i < v.size(); ++i) res += v[i];
    return res;
}

/////////////////////////////////////////////////////////
// print like python
// https://qiita.com/Lily0727K/items/06cb1d6da8a436369eed
/////////////////////////////////////////////////////////
void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << " ";
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T>& vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << " ";
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>>& df) {
    for (auto& vec : df) {
        print(vec);
    }
}

#pragma endregion Region_1
/////////////////////////////////////////////////////////

/**
 * 素因数分解
 * 素数とその個数をペアにしたリストを返す
 */
vector<pair<ll, int>> primeFactorize(ll n) {
    if (n <= 1) {
        return {};
    }
    vector<pair<ll, int>> res;
    ll x = n;

    for (ll i = 2; i * i <= n; i++) {
        if (x == 1) break;
        if (x % i != 0) continue;
        int cnt = 0;

        while (x % i == 0) {
            cnt++;
            x /= i;
        }
        res.emplace_back(i, cnt);
    }
    if (x > 1) {
        res.emplace_back(x, 1);
    }
    return res;
}

bool isHeiho(int x) {
    if (x <= 1) return true;

    for (auto v : primeFactorize(x)) {
        if (v.second % 2 > 0) {
            return false;
        }
    }
    return true;
}

int main() {
    //入力の高速化用のコード
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    std::cout << std::setprecision(15);
    //////////////////////////////////////////

    ll k;
    cin >> k;
    double ans = 0;
    srep(i, 1, 100000000) {
        ans += (double)1 / (double)i - (double)1 / (double)(i + k);
    }

    print(ans / k);

    return 0;
}
0