top1编程
← 返回题目
题解

级数求和

1 条题解

  • 0
    @ 2026-7-28 22:45:14
    #include <bits/stdc++.h>  
    using namespace std;  
    
    int main() {  
        ios::sync_with_stdio(0);  
        cin.tie(0);  
        cout.tie(0);  
    
        int k;  
        double s = 0;  
        cin >> k;  
    
        for (long long i = 1; i <= 1000000000; i++) {  
            s += 1.0 / i;  
            if (s > k) {  
                cout << i << endl;  
                break;  
            }  
        }  
    
        return 0;  
    }
    
    • 1