zoukankan      html  css  js  c++  java
  • HDU 5901 Count primes 大素数计数

    **题意:**计算1~N间素数的个数(N<=1e11) **题解:**题目要求很简单,作为论文题,模板有两种 \(O(n^frac{3}{4} )\),另一种lehmer\(O(n^frac{2}{3})\) [link:https://zh.wikipedia.org/wiki/%E7%B4%A0%E6%95%B0%E8%AE%A1%E6%95%B0%E5%87%BD%E6%95%B0](https://zh.wikipedia.org/wiki/%E7%B4%A0%E6%95%B0%E8%AE%A1%E6%95%B0%E5%87%BD%E6%95%B0)
    /** @Date    : 2016-11-18-13.59
    * @Author : Lweleth (SoungEarlf@gmail.com)
    * @Link : https://github.com/
    * @Version :
    */
    #include <stdio.h>
    #include <iostream>
    #include <string.h>
    #include <algorithm>
    #include <utility>
    #include <vector>
    #include <map>
    #include <set>
    #include <string>
    #include <stack>
    #include <math.h>
    #include <queue>
    //#include<bits/stdc++.h>
    #define LL long long
    #define MMF(x) memset((x),0,sizeof(x))
    #define MMI(x) memset((x), INF, sizeof(x))
    using namespace std;

    const int INF = 0x3f3f3f3f;
    const int N = 1e6+2000;
    using namespace std;
    //high[i] means pi(n/i),low[i] means pi(i)
    LL high[340000];
    LL low[340000];
    LL n;
    LL fun()
    {
    LL i,m,p,s,x;
    for(m = 1; m * m <= n; m++)
    high[m] = n/m-1;
    for(i = 1;i <= m; i++)
    low[i] = i-1;
    for(p = 2; p <= m; p++)
    {
    if(low[p] == low[p-1])
    continue;
    s = min(n/(p*p),m-1);
    for(x = 1; x <= s; x++)
    {
    if(x*p <= m-1)
    high[x] -= high[x*p] - low[p-1];
    else
    high[x] -= low[n/(x*p)] - low[p-1];
    }
    for(x = m; x >= p*p; x--)
    low[x] -= low[x/p] - low[p-1];
    }
    }

    int main()
    {
    while(cin>>n)
    {
    fun();
    cout << high[1] << endl;
    }
    }
  • 相关阅读:
    NotMapped属性特性
    html.EditorForModel自定义模版
    ASP.NET MVC Core的TagHelper (高级特性)
    C#静态构造函数调用机制
    ASP.NET Forms 身份认证
    特别需要注意!
    观后感
    python进阶日记(生成器)
    python进阶日记(try except)
    python进阶日记(lambda函数)
  • 原文地址:https://www.cnblogs.com/Yumesenya/p/6087136.html
Copyright © 2011-2022 走看看