STD 2015 hdu5317 打表预处理
2015-07-29 14:00
246 查看
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
Output
For each query,output the answer in a single line.
See the sample for more details.
Sample Input
2 2 3 3 5
Sample Output
1 1
暴力 + 预处理 (队友写的 完爆各种大暴力算法)
#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; }
相关文章推荐
- 存储在图的形式——邻接列表
- 逻辑串说面向对象知识点
- apktool 反编译 Input file was not found or was not readable.问题解决方案
- Win10于北京时间7月29日中午12:00正式发布
- poj 2516 Minimum Cost
- 解题笔记(30)——找含单链表的环入口点(转网上某位高手的解法)
- 红黑树的理解说明(删除)
- Android中保存和恢复Fragment状态的最好方法
- Android中保存和恢复Fragment状态的最好方法 分类: Android 2015-07-29 13:59 103人阅读 评论(0) 收藏
- 黑马程序员——Java基础——异常体系
- Git 简单使用
- log4j日志输出性能优化-缓存、异步
- (三)OGG单向DDL复制操作
- 《将博客搬至CSDN》
- 85后创办一亩田:12个月交易额从50万到100亿,估值1月1涨,红杉为
- qtableview和qtablewidget区别
- 还是畅通工程
- 面试题30——最小的k个数
- hdu1231最大连续子序列(简单的动态规划)
- 九度OJ 玛雅人的密码