【数学】Prime-Factor Prime
Prime-Factor Prime
题目描述
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.
输入
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.
输出
样例输入
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的更多相关文章
- 数学--数论--HDU2136 Largest prime factor 线性筛法变形
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- 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 ...
- HDOJ(HDU) 2136 Largest prime factor(素数筛选)
Problem Description Everybody knows any number can be combined by the prime number. Now, your task i ...
- 【沙茶了+筛选保存最大质因数】【HDU2136】Largest prime factor
Largest prime factor Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Oth ...
- (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 ...
- 2136 Largest prime factor(打表)
Problem Description Everybody knows any number can be combined by the prime number.Now, your task is ...
- Largest prime factor
problem 3:Largest prime factor 题意:求600851475143的最大的质因数 代码如下: #ifndef PRO3_H_INCLUDED #define PRO3_H_ ...
- 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 ...
- 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 ...
- 【ACM】Largest prime factor
/*打表把素数能组合的数先设置成相应的位数*/ /* if n equals two and n is No.1 position of prime factors so four position ...
随机推荐
- Tecplot如何提取三维图中某条线的数据【转载】
转载自:http://blog.sina.com.cn/s/blog_9de422500102v9by.html 截取线所在的面Data.Extract .slice from Plane,显示如下窗 ...
- mybatis-generator-gui如何打包成exe
快速阅读: 用wix和inno setup把mybatis-generator-gui 打包成exe和安装文件. 以后使用的时候方便,不用每次打开eclipse运行. 使用inno setup 5 ...
- SpringBoot-自动装配对象及源码ImportSelector分析
SpringBoot框架已经很流行了,笔者做项目也一直在用,使用久了,越来越觉得有必要理解SpringBoot框架中的一些原理了,目前的面试几乎都会用问到底层原理.我们在使用过程中基本上是搭建有一个框 ...
- docker tcp配置
1. Ubuntu Docker deamon监听tcp端口设置 https://www.jianshu.com/p/e278b0e44e1b 2. Centos https://www.cnblog ...
- 个微信小程序云开发云函数
1. project.config.json写上云函数所在目录"cloudfunctionRoot": "cloudfunctions/",如图 2. app. ...
- 复制粘贴引发的鸠占鹊巢——IDEA复制项目导致sources root复用了另一个项目
复制粘贴大法一向是程序猿的利器,但有时也会引发一些拎不清的麻烦关系来.比如我们现在想新建一个项目,为了快速而对原来的uis-gateway动用了复制粘贴大法,然后改改项目名就成了uis-applica ...
- linux简单命令2---文件搜索命令
1:文件搜索命令:locate 文件名搜索速度快,缺点不能复杂的搜索.在数据库(/var/lib/mlocate)查找.它是一天一更新.可以强制更新数据库:updatedb 2:搜索命令的命令:whe ...
- Zabbix4.x 历史数据存储到Elasticsearch7.x
一.简介 Zabbix 3.4.6 版本开始支持历史数据存储到 Elasticsearch, 早就想测试这个功能,最近有个需求需保存 zabbix 的历史数据上达十亿条,因此决定测试这功能的实用性,事 ...
- Spring Boot学习笔记——Spring Boot与Redis的集成
一.添加Redis缓存 1.添加Redis起步依赖 在pom.xml中添加Spring Boot支持Redis的依赖配置,具体如下: <dependency> <groupId> ...
- antd ——按钮
<ButtonGroup> <Button type="primary" htmlType="submit" onClick={this.ha ...