hdu 5317 RGCDQ 预处理和素因子的个数
来源:互联网 发布:java round 编辑:程序博客网 时间:2024/04/30 07:39
Description
Input
In the next T lines, each line contains L, R which is mentioned above.
All input items are integers.
1<= T <= 1000000
2<=L < R<=1000000
Output
See the sample for more details.
Sample Input
22 33 5
Sample Output
11
思路:本题给出f(x)的定义,f(x)=x的素数因子个数,然后给出一个区间[l,r],让我们求出在这个区间之内任意两个元素x1,x2,使得gcd(f(x1),f(x2))取得最大值,输出这个最大值。首先题目中只要求求出数的素数因子的个数和次数没啥关系,那我们就要发动脑筋了,2*3*5*7*11*13*17>10^6;显然所给出的数的素数因子的个数不超过7个1.首先我们模仿素数表的过程打出f(x)的表2.运用递归算出小于i的元素中因子个数为j的元素的个数3.将区间中出现的数存在数组中(出现多次的要存两次--很好懂吧),然后求最大值就好了,枚举就可以(最大也就14*14);ac:代码
#include <iostream>#include <cstdio>#include <cstring>using namespace std;int c[1000005][8],b[8]= {0,1,3,5,7,11,13,17},a[1000005];int gcd(int a,int b){ return b?gcd(b,a%b):a;}int main(){ int n,x,y; cin>>n; memset(c,0,sizeof(c)); memset(a,0,sizeof(a)); for(int i=2; i<=1000005; i++)//打素数个数表 { if(!a[i]) { for(int j=i;j<1000005;j+=i) a[j]++; } } for(int i=2; i<1000005; i++)//统计小于i的素数因子有j个的数的个数 { for(int j=1; j<=7; j++) { if(a[i]==j) c[i][j]=c[i-1][j]+1; else c[i][j]=c[i-1][j]; } } while(n--) { scanf("%d%d",&x,&y); int sum=1;int d[100]; int k=0; for(int j=7;j>=1;j--) { if(c[y][j]-c[x-1][j]>=2)//都与两个的按两个统计用于求自身和自身的gcd { d[k++]=j; d[k++]=j; } if(c[y][j]-c[x-1][j]==1) d[k++]=j; } for(int i=0;i<k;i++)//枚举 { for(int j=i+1;j<k;j++) { sum=max(sum,gcd(d[i],d[j])); } } cout<<sum<<endl; } return 0;}
- hdu 5317 RGCDQ 预处理和素因子的个数
- HDU 5317 RGCDQ (素因子分解+预处理)
- hdu 5317 RGCDQ (素因子个数的GCD)
- Hdu 5317 RGCDQ (dp+预处理)
- HDU 5317 RGCDQ(求一个区间素因子种类数的最大公约数)
- HDU 5317 RGCDQ (合数分解+预处理)
- hdu5317 RGCDQ (质因子种数+预处理)
- RGCDQ(求质因子个数+规律)
- HDU 5317 RGCDQ(素数个数 多校2015啊)
- 因子和因子个数
- hdu 5317 RGCDQ(数论素筛)
- HDU 5317 RGCDQ
- HDU 5317 RGCDQ
- hdu 5317 RGCDQ
- HDU 5317 RGCDQ
- hdu 5317 RGCDQ
- hdu 5317 RGCDQ
- HDU 5317 RGCDQ
- Python lambda
- 你应该知道的HTTP基础知识
- 养生
- 建立知识管理体系,高效学习
- 线程锁
- hdu 5317 RGCDQ 预处理和素因子的个数
- 区块链应用于再保险业创造5百万商机
- fprintf()和fscanf()
- 数据库sql优化
- 毕业这一年半,广州 and 深圳
- Linux设备驱动--添加设备节点
- wsgi测试服务器
- POJ 3174 暴力枚举
- Jersey Client API