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. 微信小程序 wxParse插件显示视频

    修改wxParse/html2json.js 文件 ,在 html2json(html, bindName) 方法里 var node = { node: 'element', tag: tag, } ...

  2. Uploadifive 上传'fileType'格式如何限制?

    Uploadifive: 'fileType':[ "application/pdf", "application/msword", "applica ...

  3. JS 将页面上的表格导出为 Excel 文件

    如果在页面上展示了一个表格,想把这个表格导出为Excel文件,那么在要求不高的情况下,可以直接利用 JavaScript 的 Blob 和 Object URL 特性将表格导出.不过,这就是利用了 E ...

  4. opencv 检测人脸、人眼

    This tutorial code’s is shown lines below. You can also download it from here . The second version ( ...

  5. linux内核中#if IS_ENABLED(CONFIG_XXX)与#ifdef CONFIG_XXX的区别

    1. #if IS_ENABLED(CONFIG_XXX) 1.1 IS_ENABLED的定义如下: /* * IS_ENABLED(CONFIG_FOO) evaluates to 1 if CON ...

  6. 【转载】 迁移学习简介(tranfer learning)

    原文地址: https://blog.csdn.net/qq_33414271/article/details/78756366 土豆洋芋山药蛋 --------------------------- ...

  7. 浅析angular,react,vue.js jQuery-1

    作者:尚春链接:https://www.zhihu.com/question/38989845/answer/79201080来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出 ...

  8. Go项目部署到服务器

    -bash: ./main: cannot execute binary file 将 go build main.go 生成的文件上传到服务器后,./main 运行后出新的报错 env GOOS=l ...

  9. node.js写巨大的xlsx

    一般用node-xlsx写xlsx文件的话局要把数据全部放在内存里面再写到文件里,如果文件很大的话就会导致内存吃不消. 可以使用PySpreadsheet这个npm库,他支持写很大的文件. PySpr ...

  10. 【Leetcode_easy】657. Robot Return to Origin

    problem 657. Robot Return to Origin 题意: solution1: class Solution { public: bool judgeCircle(string ...