//这个很好了。。。虽然是一般。。
int isp[1000100];
int p[1000100];
void init()
{
int sum=0;
int i,j;
fill(isp,isp+1000007,true);
for(i=2;i<=1000000;i++)
{
sum++;
if(!isp[i]) continue;
for(j=i+i;j<=1000000;j+=i)
{
sum++;
isp[j]=false;
}
}
int num=0;
for(i=2;i<=1000000;i++)
if(isp[i])
p[++num]=i;
}

题意:

F(x):对于x的素数因子的种类个数。

给t(<=1e6)个查询,每个查询给出L,R(<=1e6),求在区间[L,R]内求一个maxGCD(F(i),F(j))

F(i)肯定<7;

思路:

计数一下,然后后面直接搞;

用sum数组表示从1->i有数量j的个数。

最终他的个数有>=2的话可以,或者还有一种情况就是6/2或者6/3的最大公约数是2/3.后面就是手动枚举了一下。

其实弱学到的最好的就是这个线性搞出一个素数因子表。

#include <iostream>
#include <algorithm>
#include <stdio.h>
using namespace std; bool isPrime[1000001];
int cnt[1000001];
int sum[1000001][8];
void Init()
{
fill(isPrime, isPrime + 1000001, true);
for(int i = 2; i <= 1000000; ++i)
{
if(!isPrime[i])
continue;
++cnt[i];
for(int j = i + i; j <= 1000000; j += i)
{
isPrime[j] = false;
++cnt[j];
}
}
for(int i = 2; i <= 1000000; ++i)
for(int j = 1; j <= 7; ++j)
sum[i][j] = sum[i - 1][j] + (cnt[i] == j ? 1 : 0);
}
int main()
{
Init();
int T;
scanf("%d", &T);
while(T--)
{
int l, r;
scanf("%d%d", &l, &r);
int cnt[8] = {0};
for(int i = 1; i <= 7; ++i)
cnt[i] = sum[r][i] - sum[l - 1][i];
if(cnt[7] >= 2)
printf("7\n");
else if(cnt[6] >= 2)
printf("6\n");
else if(cnt[5] >= 2)
printf("5\n");
else if(cnt[4] >= 2)
printf("4\n");
else if(cnt[3] >= 2 || (cnt[3] && cnt[6]))
printf("3\n");
else if(cnt[2] >= 2 ||
(cnt[2] && cnt[4]) ||
(cnt[2] && cnt[6]) ||
(cnt[4] && cnt[6]))
printf("2\n");
else
printf("1\n");
}
return 0;
}
/*1 2 3 4 5 6 7*/
/*
7 7 7
6 6 6
5 5 5
4 4 4
3 3 3 3 6
2 2 2 2 4 2 6 4 6
*/

hdoj5317【素数预处理】的更多相关文章

  1. lightoj1259 【素数预处理】

    题意: 输出有多少对满足条件的(a,b) both a and b are prime; a+b=n a<=b; 思路: 一开始想的就是打表一个素数数组,然后还去二分..mdzz..直接判断一下 ...

  2. Codeforces 385C Bear and Prime Numbers(素数预处理)

    Codeforces 385C Bear and Prime Numbers 其实不是多值得记录的一道题,通过快速打素数表,再做前缀和的预处理,使查询的复杂度变为O(1). 但是,我在统计数组中元素出 ...

  3. Miller-Rabin素数检测算法

    遇到了一个题: Description: Goldbach's conjecture is one of the oldest and best-known unsolved problems in ...

  4. 【题解】CF264B Good Sequences

    [题解]CF264B Good Sequences 具有很明显的无后效性. 考虑\(dp\). 考虑初始条件,显然是\(dp(0)=0\) 考虑转移,显然是\(dp(t)=max(dp[k])+1\) ...

  5. 《TC训练赛一》题解!

    以下题目标题就是此题题目链接,题目内容为了节省篇幅就不粘上去了.整套题的链接:https://acm.bnu.edu.cn/v3/contest_show.php?cid=8679#info 密码:7 ...

  6. ECUST_Algorithm_2019_1

    简要题意及解析 1001 求\(a+b\). 数据范围很大,用int或者long long不行.Java和python可以使用大数直接写. 高精度加法:做法就是将数据读入字符串中,数组的每一个单元存一 ...

  7. qbxt五一数学Day3

    目录 1. 组合数取模 1. \(n,m\le 200\),\(p\) 任意 2. \(n,m\le 10^6\),\(p\ge 10^9\) 素数 3. \(n,m\le 10^6\),\(p\le ...

  8. UVA-10200-Prime Time-判断素数个数(打表预处理)+精度控制

    题意: 给出a.b区间,判断区间内素数所占百分比 思路: 注意提前打表和控制精度1e-8的范围足够用了 细节: 精度的处理 判断素数的方法(且返回值为bool) 数据类型的强制转换 保存素数个数 提前 ...

  9. hdu5317 RGCDQ (质因子种数+预处理)

    RGCDQ 题意:F(x)表示x的质因子的种数.给区间[L,R],求max(GCD(F(i),F(j)) (L≤i<j≤R).(2<=L < R<=1000000) 题解:可以 ...

随机推荐

  1. Thinking in React(翻译)

    下面是React官方文档中的Thinking inReact文章的翻译,第一次翻译英文的文章,肯定有非常多不对的地方,还望多多包涵. 原文地址:https://facebook.github.io/r ...

  2. hdu 1679 The Unique MST (克鲁斯卡尔)

    The Unique MST Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24152   Accepted: 8587 D ...

  3. HDU 4334 Trouble(哈希|线性查找)

    给定五个集合.问是否能从五个集合各取一个元素,使得元素之和为0. 这道题有两种做法,一种是哈希,然而之前没写过哈希.....比赛后从大神那copy了一份. 这里说还有一种. 对于这五个集合分为三组.1 ...

  4. 阿里云serverMySQL无法连接问题解决纪实

    作者:fbysss QQ:溜酒酒吧酒吧吾散 blog:blog.csdn.net/fbysss 声明:本文由fbysss原创,转载请注明出处 背景: 在调试程序的时候,发现数据库訪问相关的环节出现错误 ...

  5. 翻译:A Tutorial on the Device Tree (Zynq) -- Part II

    A Tutorial on the Device Tree (Zynq) -- Part II 设备树结构 Zynq的设备树如下: /dts-v1/; / { #address-cells = < ...

  6. ubuntu编译airplay

    1.alsa/asoundlib.h: No such file or directory 缺少一个库: apt-get install libasound2-dev   2.fatal error: ...

  7. 笔记整理--LibCurl开发

    LibCurl开发_未了的雨_百度空间 - Google Chrome (2013/7/26 21:11:15) LibCurl开发 一:LibCurl 编程流程1.调用curl_global_ini ...

  8. homebrew -v 或homebrew -doctor报错请检查 .bash_profile是否有误

    homebrew -doctor报错: /usr/local/Library/Homebrew/global.rb:109:in `split': invalid byte sequence in U ...

  9. bash命令中的两个横

    它是一种标记.命令中的连续的两个横表明选项已经结束了,两个横后面的内容就是参数了,不再是选项了.

  10. QT下的QThread学习(一)

    参考文档如下: http://blog.csdn.net/styyzxjq2009/article/details/8204506 上面这篇文章的开头也也出了另外两篇文章,一并看看,可以看到他的解决思 ...