【題解】Google Kick Start Round E 2021 – Increasing Sequence Card Game

【題目敘述】連結

#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int t;
long long n;

int main(){
    cin >> t;
    for (int Case = 1; Case <= t; Case++){
        cout << "Case #" << Case << ": ";
        cin >> n;
        if (n > 1000000){
            cout << setprecision(10) << log(n)+0.5772156649+(1/2/n)-(1/12/n/n) << "\n";
            continue;
        }
        double ans = 0;
        for (int i = 1; i <= n; i++){
            ans += (double)1/i;
        }
        cout << setprecision(10) << ans << "\n";
    }
}

分享本文 Share with friends