大e了 没有注意到这个问题导致超时~_~

输入a,b,c
题目:求给定数据范围[a,b]的前c小质因子的和,

#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
const int N = 1e8 + 10;
typedef long long ll;
vector<ll>res;
int a[N];
ll f(ll x)
{
    for(ll i = 2; i < 300; i ++ )//一定注意这里的, 所选取的k个最小质因数的最大值不会超过257
        if(x % i == 0)return i;
    return x;
}
int main()
{
    ll a, b, c;
    cin >> a >> b >> c;
    ll cnt = 0;
    for(ll i = a; i <= b; i ++ ) res.push_back(f(i));
    ll ans = 0;
    sort(res.begin(), res.end());
    for(int i = 0; i < c; i ++ )ans += res[i];
    cout << ans << endl;
    return 0;
}
posted @ 2021-07-20 20:51  梨花满地  阅读(38)  评论(0)    收藏  举报