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. idea出现Error configuring application listener of class org.springframework.web.context.ContextLoader

    在IDEA中写spring mvc时出现Error configuring application listener of class org.springframework.web.context. ...

  2. 2018-2019-2 网络对抗技术 20165202 Exp7 网络欺诈防范

    博客目录 一.实践目标 二.实践内容 简单应用SET工具建立冒名网站 (1分) ettercap DNS spoof (1分) 结合应用两种技术,用DNS spoof引导特定访问到冒名网站.(1.5分 ...

  3. C语言--输入输出格式

    一.PTA实验作业 题目1:7-3 温度转换 本题要求编写程序,计算华氏温度150°F对应的摄氏温度.计算公式:C=5×(F−32)/9,式中:C表示摄氏温度,F表示华氏温度,输出数据要求为整型. 1 ...

  4. spring boot + vue 前后分离实现登录功能(一)

    使用webpack 打包初始化项目 vue init webpack book-vue 进入工程目录 cd hello-vue 安装 vue-router npm install vue-router ...

  5. TynSerial图片序列(还原)

    TynSerial图片序列(还原) 笔者以生成图形验证码为例. function TForm1.VerifyCode(image: TImage): string; // 生成验证码和图像 var u ...

  6. 【Oracle/Maven】Maven导入oracle11g 自携带jdbc驱动包ojdbc6.jar到本地库

    Maven需要下载解压并添加到classpath,如果不明可以参考https://www.cnblogs.com/xiandedanteng/p/11403480.html 然后在命令行窗口执行: m ...

  7. 使用oid2name列出数据库和对应的oid

    [postgres@postgre base]$ ll total 172 drwx------ 2 postgres postgres 12288 Dec 6 09:21 1 drwx------ ...

  8. SQL-W3School-函数:SQL 函数

    ylbtech-SQL-W3School-函数:SQL 函数 1.返回顶部 1. SQL 拥有很多可用于计数和计算的内建函数. 函数的语法 内建 SQL 函数的语法是: SELECT function ...

  9. 几种主流浏览器内置http抓包工具软件使用方

    对于学习网站的人或者相关编程人员,经常需要用到http抓包工具来跟踪网页,但主流抓包软件如httpwatch.httpanalyzerstdv都是收费的,破解版往往也不稳定.实际上现在很多浏览器都内置 ...

  10. Javescript——API连接 && json数据处理(待续)

    原文链接1:How to Connect to an API with JavaScript 原文链接2:How to Use the JavaScript Fetch API to Get JSON ...