EOJ月赛-2021.4 --D. Divide(枚举质因子)
作者:互联网
题目思路:
预处理1-1e7的所有质因子
然后对区间L,R
我们算出每个质因子的个数
上述操作重复两边(两个区间)
然后check的时候对于所有的质因子是不是都满足num1[i]<=num2[i]就可以了
ll vis[10000002], p[10000002], x; void oula() { for(int i = 2 ; i <= 10000000 ; i++) { if(vis[i] == 0) p[++x] = i; for(int j = 1 ; j <= x && p[j]*i <= 10000000; j++) { vis[i * p[j]] = 1; if(i % p[j] == 0) break; } } } ll l1, r1, l2, r2, num1[10000002], num2[10000002]; void get1() { for(int i = 1 ; i <= x ; i++) { ll t = p[i]; if(t > r1) break; ll sum = 0 ; while(t <= r1) { int s1 = r1 / t; int s2 = (l1 - 1) / t; sum += s1 - s2; t = t * p[i]; } num1[i] = sum; } } void get2() { for(int i = 1 ; i <= x ; i++) { ll t = p[i]; if(t > r1) break; ll sum = 0 ; while(t <= r2) { ll s1 = r2 / t; ll s2 = (l2 - 1) / t; sum += s1 - s2; t = t * p[i]; } num2[i] = sum; } } int ok() { for(int i = 1 ; i <= x ; i++) if(num1[i] > num2[i] ) return 0; return 1; } int main() { oula(); int _ = read(); while(_--) { mst(num1, 0), mst(num2, 0); l1 = read(), r1 = read(), l2 = read(), r2 = read(); get1(), get2(); if(ok()) puts("Yes"); else puts("No"); } return 0 ; }View Code
标签:月赛,return,2021.4,--,ll,int,while,read,r1 来源: https://www.cnblogs.com/UpMing/p/14642327.html