zoukankan      html  css  js  c++  java
  • 线性筛

    https://www.luogu.org/problemnew/show/P1403

    #include<bits/stdc++.h>
    #define fi first
    #define se second
    #define INF 0x3f3f3f3f
    #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
    #define pqueue priority_queue
    #define NEW(a,b) memset(a,b,sizeof(a))
    #define lowbit(x) ((x)&(-x))
    const double pi=4.0*atan(1.0);
    const int maxn=1e6+8;
    typedef long long LL;
    typedef unsigned long long ULL;
    const LL mod=1e9+7;
    const ULL base=1e7+7;
    const double e=exp(1);
    using namespace std;
    int prime[maxn];
    bool isnotprime[maxn]={1,1};
    int d[maxn];
    int f[maxn];
    int tot=0;
    void get_prime(int n){
        for(int i=2;i<=n;i++){
            if(!isnotprime[i]){
                prime[tot++]=i;
                d[i]=i;
            }
            for(int j=0;j<tot;j++){
                if(i*prime[j]>n) break;
                isnotprime[i*prime[j]]=1;
                d[i*prime[j]]=d[i];
                if(i%prime[j]==0) break;
            }
        }
    }
    int main(){
        fio;
        int n;
        cin>>n;
        f[1]=1;
        LL sum=1;
        get_prime(n);
        for(int i=2;i<=n;i++){
            int t=2;
            int j=i/d[i];
            int now=d[i];
            while(j%d[i]==0){
                j/=d[i];
                now*=d[i];
                t++;
            }
            //cout<<i<<' '<<now<<endl;
            if(now!=i)
            d[i]=now;
            else{
                d[i]=0;
                f[i]=t;
            }
        }
        for(int i=2;i<=n;i++){
            if(!isnotprime[i]){
                f[i]=2;
            }
            else if(d[i]){
                f[i]=f[d[i]]*f[i/d[i]];
            }
            sum+=f[i];
            //cout<<i<<' '<<f[i]<<' '<<d[i]<<endl;
    
        }
        cout<<sum<<endl;
    }
  • 相关阅读:
    axios的数据请求方式及跨域
    vuex 的介绍
    返回顶部的过渡式写法
    数据结构和算法——二叉树
    RecyclerView的刷新和加载更多
    希尔排序小结
    选择排序小结
    插入排序小结
    冒泡、快速排序小结
    数据结构和算法——递归算法
  • 原文地址:https://www.cnblogs.com/Profish/p/10443417.html
Copyright © 2011-2022 走看看