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

【题解】

区间素数筛即可解决。

【队友代码】

 //
// IniAully
//
//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC optimize("O3")
#pragma GCC optimize(2)
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
#define pi acos(-1.0)
#define nl "\n"
#define pii pair<ll,ll>
#define ms(a,b) memset(a,b,sizeof(a))
#define FAST_IO ios::sync_with_stdio(NULL);cin.tie(NULL);cout.tie(NULL)
using namespace std;
typedef long long ll;
const ll mod = 1e9+;
ll qpow(ll x, ll y){ll s=;while(y){if(y&)s=s*x%mod;x=x*x%mod;y>>=;}return s;}
//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;}
inline int read(){int x=,f=;char ch=getchar();while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}while(ch>=''&&ch<='') x=x*+ch-'',ch=getchar();return x*f;} const int maxn = 1e5+;
ll vis[maxn], prime[maxn], cnt;
void isprime()
{
memset(vis,,sizeof(vis));
for(ll i=;i<maxn;i++)
{
if(!vis[i])prime[cnt++]=i;
for(ll j=;j<cnt && i*prime[j]<maxn;j++)
{
vis[i*prime[j]]=;
if(i%prime[j]==)break;
}
}
vis[] = ;
vis[] = ;
} const int N = 1e6+;
ll bas[N];
int amo[N]; int main()
{
int l, r;
isprime() ; scanf("%d%d",&l,&r);
for(int i=;i<=r-l+;i++) bas[i] = ;
for(int i=;i<cnt;i++)
{
int u = (l-)/prime[i] + ;
int v = r/prime[i];
for(int j=u;j<=v;j++)
{
int _ = j*prime[i], __=_;
while(_%prime[i]==){
amo[__-l+]++;
_ /= prime[i];
bas[__-l+] *= prime[i];
}
}
}
//cout<<1<<nl;
int ans = ;
for(int i=l;i<=r;i++)
{
if(i<=) continue;
//cout<<i<<" : "<<amo[i-l+1]<<nl;
if(bas[i-l+] != i)amo[i-l+] ++;
if(!vis[amo[i-l+]]) ans ++;
}
cout<<ans<<nl; return ;
}

【数学】Prime-Factor Prime的更多相关文章

  1. 数学--数论--HDU2136 Largest prime factor 线性筛法变形

    Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...

  2. The largest prime factor(最大质因数)

    1. 问题: The prime factors of 13195 are 5, 7, 13 and 29.What is the largest prime factor of the number ...

  3. HDOJ(HDU) 2136 Largest prime factor(素数筛选)

    Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...

  4. 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor

    Largest prime factor Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Oth ...

  5. (Problem 3)Largest prime factor

    The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...

  6. 2136 Largest prime factor(打表)

    Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...

  7. Largest prime factor

    problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_ ...

  8. Problem 3: Largest prime factor

    The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...

  9. R语言学习——欧拉计划(3)Largest prime factor 求最大质因数

    The prime factors of 13195 are 5, 7, 13 and 29. What is the largest prime factor of the number 60085 ...

  10. 【ACM】Largest prime factor

    /*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors  so four position ...

随机推荐

  1. ajax默认是异步的

    jquery中的ajax 默认情况下为异步请求,即 async:true,可以通过设置参数 asycn:false 到使其同步 $.ajax({ url: 'www.test.com/test/tes ...

  2. 【原】Python基础-循环语句

    x = 1while x <= 10: print(x) x += 1 password = ""while password != "3213554": ...

  3. l2_multi.py

    # Copyright 2012-2013 James McCauley # # Licensed under the Apache License, Version 2.0 (the "L ...

  4. sklearn.GridSearchCV选择超参

    from sklearn import datasets from sklearn.model_selection import train_test_split from sklearn.model ...

  5. Eclipse中把项目导出为war包【我】

    项目右键,Export 全部默认一路下一步,选择一个目标文件夹,确定即可.

  6. 丢失libiconv-2.dll解决办法以及无法定位输入点libiconv-2.dll到动态链接库

    摘自https://blog.csdn.net/mengxiangjia_linxi/article/details/78147348 丢失libiconv-2.dll解决办法以及无法定位输入点lib ...

  7. Django和Flask这两个框架对比

    Flask 在 Django 之后发布,现阶段有大量的插件和扩展满足不同需要 Django发布于2005年,Flask创始于2010年年中. Django功能大而全,Flask只包含基本的配置,  D ...

  8. 第六章 Realm及相关对象——《跟我学Shiro》

    转发地址:https://www.iteye.com/blog/jinnianshilongnian-2022468 目录贴:跟我学Shiro目录贴 6.1 Realm [2.5 Realm]及[3. ...

  9. golang 日志模块(log)

    log 日志 log 模块可以自定义log 对象, 也可以使用log默认对象的日志方法 func New 创建log对象 func New(out io.Writer, prefix string, ...

  10. .git泄露及利用php弱类型松散比较构造json的payload

    一道ctf题,文章搬运到了自己的网站上: http://101.132.137.140:202/archives/2019-11-16