STD 2015 hdu5317 打表预处理
来源:互联网 发布:java 策略模式 编辑:程序博客网 时间:2024/05/17 07:30
RGCDQ
Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1146 Accepted Submission(s): 516
Problem Description
Mr. Hdu is interested in Greatest Common Divisor (GCD). He wants to find more and more interesting things about GCD. Today He comes up with Range Greatest Common Divisor Query (RGCDQ). What’s RGCDQ? Please let me explain it to you gradually. For a positive integer x, F(x) indicates the number of kind of prime factor of x. For example F(2)=1. F(10)=2, because 10=2*5. F(12)=2, because 12=2*2*3, there are two kinds of prime factor. For each query, we will get an interval [L, R], Hdu wants to know maxGCD(F(i),F(j)) (L≤i<j≤R)
Input
There are multiple queries. In the first line of the input file there is an integer T indicates the number of queries.
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
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
For each query,output the answer in a single line.
See the sample for more details.
See the sample for more details.
Sample Input
22 33 5
Sample Output
11
暴力 + 预处理 (队友写的 完爆各种大暴力算法)
#include <stdio.h>#include <iostream>#include <string.h>#include <stack>#include <algorithm>using namespace std;const int M = 1e6 + 5;int a[M]= {0};int pr[M][9];int z[10]={0};int gcd (int x,int y){ return y==0 ? x : gcd(y,x%y);}void init(){ for(int i = 2; i < M; i++) { if(!a[i]) { for(int j = i + i; j < M; j+=i) { a[j]++; } a[i] = 1 ; } z[a[i]]=i; pr[i][1]=z[1]; pr[i][2]=z[2]; pr[i][3]=z[3]; pr[i][4]=z[4]; pr[i][5]=z[5]; pr[i][6]=z[6]; pr[i][7]=z[7]; pr[i][8]=z[8]; }}int main(){ init(); int t; scanf("%d",&t); while(t--) { int x,y; scanf("%d%d",&x,&y);// printf("%I64d %I64d",a[x],a[y]); int _max=1; if (pr[y][2]>=x) { if (pr[(pr[y][2]-1)][2]>=x || pr[y][4]>=x || pr[y][6]>=x) _max=2; } if (pr[y][3]>=x) { if (pr[(pr[y][3]-1)][3]>=x || pr[y][6]>=x) _max=3; } if (pr[y][4]>=x) { if (pr[(pr[y][4]-1)][4]>=x) _max=4; if (_max==1 && pr[y][6]>=x) _max=2; } if (pr[y][5]>=x) if (pr[(pr[y][5]-1)][5]>=x && pr[y][5]>=x) _max=5; if (pr[y][6]>=x && pr[(pr[y][6]-1)][6]>=x) _max=6; if (pr[y][7]>=x && pr[(pr[y][7]-1)][7]>=x) _max=7; printf("%d\n",_max); } return 0;}
0 0
- STD 2015 hdu5317 打表预处理
- hdu5317 素数筛预处理
- hdu5317 RGCDQ (质因子种数+预处理)
- HDU2089(打表预处理)
- HDU5317
- HDU 5879 Cure(打表预处理)
- 【HDU 1128 Self Numbers】+ 打表预处理
- 预处理指令using namespace std
- CSUOJ 1299 - Number Transformation II 打表预处理水DP
- 116 Super-Prime(完全背包+打表预处理)
- HDU 4548 美素数(打表+预处理)
- HDU 4548.美素数【打表】【预处理】【8月11】
- UESTC 1299 Date 预处理、打表、找周期、前缀和
- HDU 4151The Special Number(预处理打表+二分)
- FZU 2037Maximum Value Problem (打表预处理/找规律)
- ZOJ 3939The Lucky Week (打表预处理/找规律)
- 【cdoj 1323】柱爷的下凡 dp打表预处理
- hdu 5878 I Count Two Three【预处理打表+二分】
- log4j日志输出性能优化-缓存、异步
- (三)OGG单向DDL复制操作
- Git 简单使用
- C语言tips
- iOS开发,更改状态栏(StatusBar)文字颜色为白色
- STD 2015 hdu5317 打表预处理
- 畅通工程
- 红黑树的理解说明(删除)
- 57. Insert Interval
- 解题笔记(30)——找含单链表的环入口点(转网上某位高手的解法)
- Atom飞行手册翻译: 1.4 小结
- 写在Demo战斗系统之前,先用原型工具做套UI第三篇-常规UI界面制作
- linux上安装SVN
- HDU 2120--Ice_cream's world I【并查集, 判断环的个数】