• 【数学】Prime-Factor Prime


    Prime-Factor Prime

    题目描述

    A positive integer is called a "prime-factor prime" when the number of its prime factors is prime. For example, 12 is a prime-factor prime because the number of prime factors of 12=2×2×3 is 3, which is prime. On the other hand, 210 is not a prime-factor prime because the number of prime factors of 210=2×3×5×7 is 4, which is a composite number.

    In this problem, you are given an integer interval [l,r]. Your task is to write a program which counts the number of prime-factor prime numbers in the interval, i.e. the number of prime-factor prime numbers between l and r, inclusive.

    输入

    The input consists of a single test case formatted as follows.

    l r
    A line contains two integers l and r (1≤l≤r≤109), which presents an integer interval [l,r]. You can assume that 0≤r−l<1,000,000.

    输出

    Print the number of prime-factor prime numbers in [l,r].

    样例输入

    1 9
    

    样例输出

    4


     

    【题解】

    区间素数筛即可解决。

    【队友代码】

     1 //
     2 //  IniAully
     3 //
     4 //#pragma GCC optimize("Ofast,no-stack-protector")
     5 //#pragma GCC optimize("O3")
     6 #pragma GCC optimize(2)
     7 #include <bits/stdc++.h>
     8 #define inf 0x3f3f3f3f
     9 #define linf 0x3f3f3f3f3f3f3f3fll
    10 #define pi acos(-1.0)
    11 #define nl "
    "
    12 #define pii pair<ll,ll>
    13 #define ms(a,b) memset(a,b,sizeof(a))
    14 #define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
    15 using namespace std;
    16 typedef long long ll;
    17 const ll mod = 1e9+7;
    18 ll qpow(ll x, ll y){ll s=1;while(y){if(y&1)s=s*x%mod;x=x*x%mod;y>>=1;}return s;}
    19 //ll qpow(ll a, ll b){ll s=1;while(b>0){if(b%2==1)s=s*a;a=a*a;b=b>>1;}return s;}
    20 inline int read(){int x=0,f=1;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();return x*f;}
    21   
    22 const int maxn = 1e5+5;
    23 ll vis[maxn], prime[maxn], cnt;
    24 void isprime()
    25 {
    26     memset(vis,0,sizeof(vis));
    27     for(ll i=2;i<maxn;i++)
    28     {
    29         if(!vis[i])prime[cnt++]=i;
    30         for(ll j=0;j<cnt && i*prime[j]<maxn;j++)
    31         {
    32             vis[i*prime[j]]=1;
    33             if(i%prime[j]==0)break;
    34         }
    35     }
    36     vis[1] = 1;
    37     vis[0] = 1;
    38 }
    39   
    40 const int N = 1e6+5;
    41 ll bas[N];
    42 int amo[N];
    43   
    44 int main()
    45 {
    46     int l, r;
    47     isprime() ;
    48   
    49     scanf("%d%d",&l,&r);
    50     for(int i=0;i<=r-l+5;i++) bas[i] = 1;
    51     for(int i=0;i<cnt;i++)
    52     {
    53         int u = (l-1)/prime[i] + 1;
    54         int v = r/prime[i];
    55         for(int j=u;j<=v;j++)
    56         {
    57             int _ = j*prime[i], __=_;
    58             while(_%prime[i]==0){
    59                 amo[__-l+1]++;
    60                 _ /= prime[i];
    61                 bas[__-l+1] *= prime[i];
    62             }
    63         }
    64     }
    65     //cout<<1<<nl;
    66     int ans = 0;
    67     for(int i=l;i<=r;i++)
    68     {
    69         if(i<=3) continue;
    70         //cout<<i<<" : "<<amo[i-l+1]<<nl;
    71         if(bas[i-l+1] != i)amo[i-l+1] ++;
    72         if(!vis[amo[i-l+1]]) ans ++;
    73     }
    74     cout<<ans<<nl;
    75   
    76     return 0;
    77 }
    View Code
  • 相关阅读:
    Linux----------系统管理之释放内存
    阿里云OSS挂载到ECS(注意fuse版本,必须和源码对应)
    数据库图形化管理工具navicat
    linux集群管理工具clustershell
    记一次nginx启动报错
    虚拟化之KVM
    虚拟化之-XEN(未完待续)
    虚拟化
    Linux----------Jenkins基础
    Linux日常系统管理命令
  • 原文地址:https://www.cnblogs.com/Osea/p/11397653.html
Copyright © 2020-2023  润新知