• 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
    ",ans);
        return 0;
    }
    /*
    */
  • 相关阅读:
    CF Round #427 (Div. 2) C. Star sky [dp]
    顺时针打印矩阵
    堆 栈-相关知识【转】
    二叉树的镜像
    树的子结构
    合并两个排序的链表
    数值的整数次方
    位运算:二进制中1的个数
    斐波那契数列及其变形
    重建二叉树
  • 原文地址:https://www.cnblogs.com/CJLHY/p/10513795.html
Copyright © 2020-2023  润新知