Codeforces 1017F The Neutral Zone (看题解)

这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作。

#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long
using namespace std;

const int N = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + 7;
const double eps = 1e-8;

unsigned int n,a,b,c,d;
unsigned int ans;
bitset<100000001> bit;

inline unsigned int f(unsigned int x){
    return a * x * x * x + b * x * x + c * x + d;
}
inline unsigned int getVal(unsigned int x){
    unsigned int ret = f(x);
    unsigned int tmp = 0;
    for(unsigned int i = n / x; i; i /= x)
        tmp += i;
    return ret * tmp;
}

int main(){
    scanf("%u%u%u%u%u",&n,&a,&b,&c,&d);
    ans = getVal(2) + getVal(3);
    bit.reset();
    for(unsigned int i = 5; i <= n; i++){
        if(i % 2 == 0 || i % 3 == 0) {
            continue;
        }
        if(bit[i / 3] == 0) {
            ans += getVal(i);
            for(unsigned int j = i; j <= n; j += i){
                if(j % 2 == 0 || j % 3 == 0) continue;
                bit[j / 3] = 1;
            }
        }
    }
    printf("%u\n",ans);
    return 0;
}
/*
*/

 

posted @ 2019-03-11 22:45  NotNight  阅读(191)  评论(0编辑  收藏  举报