【数学】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 ...
随机推荐
- Java 代码里乱打日志了,这才是正确的打日志姿势
使用slf4j 使用门面模式的日志框架,有利于维护和各个类的日志处理方式统一. 实现方式统一使用: Logback框架 打日志的正确方式 什么时候应该打日志 当你遇到问题的时候,只能通过debug功能 ...
- GCC与GDB使用
GCC基本命令 gcc[选项][文件名] -E:仅执行编译预处理(.c->.i) -S:将c代码转换成汇编代码(.i->.s) -c:仅执行编译操作,不进行连接操作(.s->.o) ...
- arcgis python ValueTable使用
本文链接:https://blog.csdn.net/A873054267/article/details/86007125 #多值参数指定方式 1 python list类型 2 字符串类型,以逗号 ...
- 续--Flask, Django - 区别
1. 目录结构 参考:https://blog.csdn.net/yang9520/article/details/79740374 中文文档(http://docs.jinkan.o ...
- [java]三种自定义链表排序方式
代码: import java.util.ArrayList; import java.util.Comparator; import java.util.List; class Emp{ Strin ...
- P1964 【mc生存】卖东西
P1964 [mc生存]卖东西 题解 很简单, 暴力 注意一个小点就好 代码 #include<iostream> #include<cstdio> #include<c ...
- 阶段5 3.微服务项目【学成在线】_day08 课程图片管理 分布式文件系统_06-分布式文件系统研究-fastDFS安装及配置文件说明
3 fastDFS入门 3.1fastDFS安装与配置 3.1.1 导入虚拟机 对fastDFS的安装过程不要求学生掌握,可以直接导入老师提供虚拟机. 1.使用Vmware打开虚拟机配置文件“Cent ...
- Lombok子类与父类的@Builder注解冲突
解决方法之一:去掉父类的@builder 缺点:父类不能使用Builder构造器模式 来源:https://www.cnblogs.com/lori/p/10266508.html
- LeetCode_53. Maximum Subarray
53. Maximum Subarray Easy Given an integer array nums, find the contiguous subarray (containing at l ...
- (1) Java实现JDBC连接及事务的方式
许多数据库的auto-commit默认是ON的,比如MySQL,PostgresSQL等.当然也有默认是OFF的,比如Oracle(Oracle里面执行DML语句是需要手动commit的). 这里我们 ...