全错!这高精度怎么简单算 ?

P1009 [NOIP1998 普及组] 阶乘之和

Yu09217777 @ 2022-10-07 11:32:59

#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,sum,t;
    cin >> n;
    for(int i = 1;i <= n;i++){
        for(int j = i;j >= 1;j--){
            t *= j;
        }
        sum += t;
        t = 1;  
    }
    cout << sum;
    return 0;
}

by 262620zzj @ 2022-10-07 11:50:06

@Yu09217777 只需要高精度加和乘,还挺简单的吧


by yh2022mayu @ 2022-10-07 11:51:38

vector<int> mul(vector<int> &a, long long &b){
    vector<int> c;
    int t = 0;
    for (int i = 0; i < a.size() || t > 0; i++){
        if(i < a.size()) t += a[i] * b;
        c.push_back(t % 10);
        t /= 10;
    }
    while(c.size() > 1 && c[c.size() - 1] == 0) c.pop_back();
    return c;
}

高精乘法(个人写法


by Yu09217777 @ 2022-10-07 11:52:00

感谢各位,只能继续学习更高的知识了


by 喵仔牛奶 @ 2022-10-07 11:53:14

加油(ง •_•)ง


by yh2022mayu @ 2022-10-07 11:55:30

加油加油!!


by yh2022mayu @ 2022-10-07 11:57:08

你要注意高精度除了除法,其他都倒着存会方便一点


上一页 |