洛谷 1072 Hankson 的趣味题——质因数界限讨论
题目:https://www.luogu.org/problemnew/show/P1072
思路是把每个数质因数分解,答案对于每个质因数的次数有选择的区间,通过这个计算。
指数的限制就是上限是b1,下限是a1;a0-a1后有剩余的自己不能有;b1-b0有剩余的自己不能剩(即必须满上限)。
分解质因数用了那个好像是 O( n^(1/4) ) 的方法。其实如果给的都是大质数是不是会被卡?
然后写了无比冗长的代码。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=;
int T,a0,a1,b0,b1,p[N],tot,hi[N],lo[N],hi2[N],lo2[N],lm[N],ans;
bool flag=;
int rdn()
{
int ret=;bool fx=;char ch=getchar();
while(ch>''||ch<''){if(ch=='-')fx=;ch=getchar();}
while(ch>=''&&ch<='') ret=(ret<<)+(ret<<)+ch-'',ch=getchar();
return fx?ret:-ret;
}
int main()
{
T=rdn();
while(T--)
{
a0=rdn(); a1=rdn(); b0=rdn(); b1=rdn();
int n=b1; tot=;//limit
for(int i=;i*i<=n;i++)
{
if(n%i==)
{
p[++tot]=i;lo[tot]=hi[tot]=lo2[tot]=hi2[tot]=;
while(n%i==)n/=i,hi[tot]++;
hi2[tot]=hi[tot];
}
}
if(n>)
{
p[++tot]=n;lo[tot]=hi[tot]=lo2[tot]=hi2[tot]=;
hi[tot]=hi2[tot]=;
} flag=;
n=a1; int p0=;//bottom
for(int i=;i*i<=n;i++)
if(n%i==)
{
int d=;
while(n%i==)n/=i,d++;
while(p0<tot&&p[p0]<i)p0++;
if(p[p0]!=i){flag=;break;}
lo[p0]=d;
}
if(flag){puts("");continue;}
if(n>)
{
while(p0<tot&&p[p0]<n)p0++;
if(p[p0]==n)
lo[p0]=;
} flag=;
for(int i=;i<=tot;i++)if(hi[i]<lo[i]){flag=;break;}
if(flag){puts("");continue;} n=b0; p0=;
for(int i=;i*i<=n;i++)
{
if(n%i==)
{
int d=;
while(n%i==)n/=i,d++;
while(p0<tot&&p[p0]<i)p0++;
if(p[p0]!=i)continue;
lo2[p0]=d;//can't leave
}
}
if(n>)
{
while(p0<tot&&p[p0]<n)p0++;
if(p[p0]==n) lo2[p0]=;
}
for(int i=;i<=tot;i++)
{
int d=hi[i]-lo2[i];
if(d) lo2[i]=hi[i]; else lo2[i]=;
} n=a0; p0=;
for(int i=;i*i<=n;i++)
{
if(n%i==)
{
int d=;
while(n%i==)n/=i,d++;
while(p0<tot&&p[p0]<i)p0++;
if(p[p0]!=i)continue;
if(d>lo[p0])hi2[p0]=lo[p0];//can't exist
}
}
if(n>)
{
while(p0<tot&&p[p0]<n)p0++;
if(p[p0]==n)
if(>lo[p0])hi2[p0]=lo[p0];
} for(int i=;i<=tot;i++)
hi[i]=min(hi[i],hi2[i]),lo[i]=max(lo[i],lo2[i]);
ans=; flag=;
for(int i=;i<=tot;i++)
{
if(lo[i]>hi[i]){flag=;break;}
ans*=hi[i]-lo[i]+;
}
printf("%d\n",flag?ans:);
}
return ;
}
洛谷 1072 Hankson 的趣味题——质因数界限讨论的更多相关文章
- 洛谷 - P1072 Hankson - 的趣味题 - 质因数分解
https://www.luogu.org/problemnew/show/P1072 一开始看了一看居然还想放弃了的. 把 \(x,a_0,a_1,b_0,b_1\) 质因数分解. 例如 \(x=p ...
- 洛谷 P1072 Hankson 的趣味题 —— 质因数分解
题目:https://www.luogu.org/problemnew/show/P1072 满足条件的数 x 一定是 a1 的倍数,b1 的因数,a0/a1 与 x/a1 互质,b1/b0 与 b1 ...
- 洛谷 P1072 Hankson 的趣味题 解题报告
P1072 \(Hankson\)的趣味题 题目大意:已知有\(n\)组\(a0,a1,b0,b1\),求满足\((x,a0)=a1\),\([x,b0]=b1\)的\(x\)的个数. 数据范围:\( ...
- 洛谷P1072 Hankson 的趣味题
P1072 Hankson 的趣味题 题目描述 Hanks 博士是 BT (Bio-Tech,生物技术) 领域的知名专家,他的儿子名叫 Hankson.现在,刚刚放学回家的 Hankson 正在思考一 ...
- Java实现洛谷 P1072 Hankson 的趣味题
P1072 Hankson 的趣味题 输入输出样例 输入 2 41 1 96 288 95 1 37 1776 输出 6 2 PS: 通过辗转相除法的推导 import java.util.*; cl ...
- 【题解】洛谷P1072 Hankson的趣味题 (gcd和lcm的应用)
洛谷P1072:https://www.luogu.org/problemnew/show/P1072 思路 gcd(x,a0)=a1 lcm(x,b0)=b1→b0*x=b1*gcd(x,b0) ( ...
- 洛谷 P1072 Hankson 的趣味题 || 打质数表的分解质因数
方法就是枚举,根据b0和b1可以大大减小枚举范围,方法类似这个http://blog.csdn.net/hehe_54321/article/details/76021615 将b0和b1都分解质因数 ...
- 洛谷P1072 Hankson 的趣味题(题解)
https://www.luogu.org/problemnew/show/P1072(题目传送) 数学的推理在编程的体现越来越明显了.(本人嘀咕) 首先,我们知道这两个等式: (a0,x)=a1,[ ...
- 洛谷P1072 Hankson的趣味题
这是个NOIP原题... 题意: 给定 a b c d 求 gcd(a, x) = b && lcm(c, x) = d 的x的个数. 可以发现一个朴素算法是从b到d枚举,期望得分50 ...
随机推荐
- Debian Customer PPA RFC (by quqi99)
作者:张华 发表于:2016-01-13版权声明:能够随意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本版权声明 ( http://blog.csdn.net/quqi99 ) Pre ...
- 车牌识别--OMAP4430处理器上測试
OMAP4430(ME865) arm-linux-gcc 4.5.1(FriendlyARM) 软浮点执行结果: root@lj:/workspace/carid# arm-linux-gcc ca ...
- 无线(仅WIFI)攻击思路总结
从事信息安全相关工作5年了,虽然主要工作是安全产品售前.安全服务等方向,但既然选择了安全,想必都是有点黑客情节的,因此也前前后后杂七杂八的学了点东西.最近在研究无线(主要是WIFI)安全,相关书籍看了 ...
- 03 http+socket编程批量发帖
<?php // http请求类的接口 interface Proto { // 连接url function conn($url); //发送get查询 function get(); // ...
- React Native组件解析(二)之Text
React Native组件解析(二)之Text 1. 概述 Text组件对应于iOS的UILabel,Android的TextView,用来显示文本.但是Text组件的内部使用的并不是flexbox ...
- CentOS系统时间修改
1. 实体机器上安装CentOS $date -s '2015-03-03 13:34:00' 2. 虚拟机上安装的CentOS #查看系统时间和硬件时间 date hwclock --show #设 ...
- [转]***换机房换ip之后不能连外网
***换机房换ip之后不能连外网 时间 2015-07-21 15:17:16 Wendal随笔 原文 http://wendal.net/2015/07/21.html 主题 iptables ...
- 解决用EasyDarwin开源流媒体服务器做HLS直播时Flash Player卡住的问题
最近在开发EasyDarwin开源流媒体服务器HLS直播的时候发现一个现象:在PC上用flash player播放HLS和在ios上面播放HLS时,效果明显不同,在ios上播放非常稳定,而在flash ...
- EasyPusher:基于live555的DarwinInjector实现的RTSP直播推送程序
先简单介绍一下EasyPusher的功能,后面再对具体内部架构做介绍: EasyPusher:https://github.com/EasyDarwin/EasyPusher EasyPusher是什 ...
- live555中fDurationInMicroseconds的计算
live555中fDurationInMicroseconds表示单个视频或者音频帧所占用的时间间隔,也表示在fDurationInMicroseconds微秒时间后再次向Source进行getNex ...