zoukankan      html  css  js  c++  java
  • 【CF1017F】The Neutral Zone(Bitset,埃氏筛)

    题意:

    思路:From https://blog.csdn.net/CSDNjiangshan/article/details/81536536

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 #include<bitset>
    12 using namespace std;
    13 typedef long long ll;
    14 typedef unsigned int uint;
    15 typedef unsigned long long ull;
    16 typedef pair<int,int> PII;
    17 typedef vector<int> VI;
    18 #define fi first
    19 #define se second 
    20 #define MP make_pair
    21 #define N      110000000
    22 #define M      51
    23 #define MOD 1000000007
    24 #define eps 1e-8 
    25 #define pi     acos(-1)
    26 #define oo     3e14
    27 
    28 uint n,a,b,c,d;
    29 bitset<N> p;
    30 
    31 uint f(uint x)
    32 {
    33     return a*x*x*x+b*x*x+c*x+d;
    34 }
    35 
    36 uint calc(uint x)
    37 {
    38     uint k=n;
    39     uint ans=0;
    40     while(k)
    41     {
    42         ans+=k/x;;
    43         k/=x;
    44     }
    45     ans*=f(x);
    46     return ans;
    47 }
    48 
    49 int main()
    50 { 
    51     scanf("%u%u%u%u%u",&n,&a,&b,&c,&d);
    52     ull ans=calc(2)+calc(3);
    53     p.reset();
    54     for(uint i=5;i<=n;i++)
    55     {
    56         if(i%2==0||i%3==0) continue;
    57         if(p[i/3]==0)
    58         {
    59             ans+=calc(i);
    60             for(uint j=2;j<=n/i;j++)
    61             {
    62                 if(i*j%2==0||i*j%3==0) continue;
    63                 p[i*j/3]=1;
    64             }
    65         }
    66     }
    67     printf("%u",ans);
    68     return 0;
    69 }
  • 相关阅读:
    反向迭代
    c++知识点
    LeetCode-Count Bits
    LeetCode-Perfect Rectangle
    LeetCode-Perfect Squares
    LeetCode-Lexicographical Numbers
    LeetCode-Find Median from Data Stream
    LeetCode-Maximal Square
    LeetCode-Number of Digit One
    LeetCode-Combination Sum IV
  • 原文地址:https://www.cnblogs.com/myx12345/p/10071332.html
Copyright © 2011-2022 走看看